Skip to content

Instantly share code, notes, and snippets.

@flazz
Created July 21, 2010 22:17
Show Gist options
  • Save flazz/485229 to your computer and use it in GitHub Desktop.
Save flazz/485229 to your computer and use it in GitHub Desktop.
newtype State s a = State { runState :: (s -> (a,s)) }
instance Monad (State s) where
return a = State $ \s -> (a,s)
(State x) >>= f = State $ \s -> let (v,s') = x s
in runState (f v) s'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment