Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created November 12, 2009 03:44
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/232575 to your computer and use it in GitHub Desktop.
Save jutememo/232575 to your computer and use it in GitHub Desktop.
module Stack(Stack, empty, empty', pop, push, push') where
newtype Stack a = Stack [a] deriving Show
empty :: Stack a
empty = Stack []
empty' :: Stack a -> ((), Stack a)
empty' _ = ((), Stack [])
pop :: Stack a -> (a, Stack a)
pop (Stack (x:xs)) = (x, Stack xs)
push :: a -> Stack a -> Stack a
push x (Stack xs) = Stack (x:xs)
push' :: a -> Stack a -> ((), Stack a)
push' x (Stack xs) = ((), Stack (x:xs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment