[project @ 1999-01-23 17:57:35 by sof]
[ghc-hetmet.git] / ghc / tests / typecheck / should_compile / tc093.hs
1 module ShouldSucceed where
2
3 data State c a = State (c -> (a,c))
4
5 unState :: State c a -> (c -> (a,c))
6 unState (State x) = x
7
8 unitState :: a -> State c a
9 unitState a = State (\s0 -> (a,s0))
10
11 bindState :: State c a -> (a -> State c b) -> State c b
12 bindState m k = State (\s0 -> let (a,s1) = (unState m) s0
13                                   (b,s2) = (unState (k a)) s1 
14                               in (b,s2))
15
16 instance Eq c => Monad (State c) where
17     return = unitState 
18     (>>=)  = bindState 
19
20 data TS = TS { vs::Int } deriving (Show,Eq)
21
22 type St a = State TS a
23
24 foo :: Int -> St Int  -- it works if this line is not given
25 foo x = return x