Commit 452cba44 authored by twanvl's avatar twanvl
Browse files

Added Applicative and Functor instances for State monad

parent e2f9c3d7
module State where
import MonadUtils
newtype State s a = State { runState' :: s -> (# a, s #) }
instance Functor (State s) where
fmap f m = State $ \s -> case runState' m s of
(# r, s' #) -> (# f r, s' #)
instance Applicative (State s) where
pure x = State $ \s -> (# x, s #)
m <*> n = State $ \s -> case runState' m s of
(# f, s' #) -> case runState' n s' of
(# x, s'' #) -> (# f x, s'' #)
instance Monad (State s) where
return x = State $ \s -> (# x, s #)
m >>= n = State $ \s -> case runState' m s of
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment