blob: c834428b20d871ea05e611beb7e22e8bd1df7aef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
module ShouldSucceed where
data State c a = State (c -> (a,c))
unState :: State c a -> (c -> (a,c))
unState (State x) = x
unitState :: a -> State c a
unitState a = State (\s0 -> (a,s0))
bindState :: State c a -> (a -> State c b) -> State c b
bindState m k = State (\s0 -> let (a,s1) = (unState m) s0
(b,s2) = (unState (k a)) s1
in (b,s2))
instance Eq c => Monad (State c) where
return = unitState
(>>=) = bindState
data TS = TS { vs::Int } deriving (Show,Eq)
type St a = State TS a
foo :: Int -> St Int -- it works if this line is not given
foo x = return x
|