Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created October 14, 2009 02:14
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/209725 to your computer and use it in GitHub Desktop.
Save jutememo/209725 to your computer and use it in GitHub Desktop.
module Stack(Stack, empty, empty', pop, push, push', s) 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))
s = push 5 $ push 4 $ push 3 $ push 2 $ push 1 $ empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment