7b048eb2dfddd59cbb5c0376dcfaccc426e5ddff
[ghc.git] / testsuite / tests / typecheck / should_run / T1735_Help / State.hs
1
2 module T1735_Help.State where
3
4 newtype StateT s m a = StateT { runStateT :: s -> m (a,s) }
5
6 instance Monad m => Monad (StateT s m) where
7 return a = StateT $ \s -> return (a, s)
8 m >>= k = StateT $ \s -> do
9 ~(a, s') <- runStateT m s
10 runStateT (k a) s'
11 fail str = StateT $ \_ -> fail str
12
13 get :: Monad m => StateT s m s
14 get = StateT $ \s -> return (s, s)
15
16 put :: Monad m => s -> StateT s m ()
17 put s = StateT $ \_ -> return ((), s)
18