Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created November 10, 2009 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jutememo/230587 to your computer and use it in GitHub Desktop.
Save jutememo/230587 to your computer and use it in GitHub Desktop.
module State (State, comb, comb_, ret) where
type State s a = s -> (a, s)
comb :: State s a -> (a -> State s b) -> State s b
comb m n = \s0 -> let (x1, s1) = m s0
(x2, s2) = n x1 s1
in (x2, s2)
comb_ :: State s a -> State s b -> State s b
comb_ m n = m `comb` \_ -> n
ret :: a -> State s a
ret x = \s -> (x, s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment