Skip to content

Instantly share code, notes, and snippets.

@echaozh
Last active August 29, 2015 13:57
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 echaozh/9349531 to your computer and use it in GitHub Desktop.
Save echaozh/9349531 to your computer and use it in GitHub Desktop.
{-# LANGUAGE PackageImports, UnicodeSyntax #-}
import "mtl" Control.Monad.State
type Stack a b = State [a] b
push ∷ a → Stack a ()
push a = modify (a:)
pop ∷ Stack a a
pop = do
a : as ← get
put as
return a
testStack ∷ Stack Int String
testStack = do
push 1
push 2
push 3
pop
return "I am not a stack builder!"
main = print $ execState testStack []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment