Skip to content

Instantly share code, notes, and snippets.

@GoldsteinE
Created March 17, 2020 20:55
Show Gist options
  • Save GoldsteinE/db3f95b358b68c0da41014155de6b604 to your computer and use it in GitHub Desktop.
Save GoldsteinE/db3f95b358b68c0da41014155de6b604 to your computer and use it in GitHub Desktop.
newtype State s a = State { runState :: s -> (a, s) }
instance Monad (State s) where
(State x) >>= f = State $ \s ->
let (a, s') = x s
(State x') = f a
in x' s'
instance Applicative (State s) where
pure x = State $ \s -> (x, s)
(<*>) = ap
instance Functor (State s) where
fmap = liftM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment