
Not using Stack for anything, just trying to understand how things can be done in Haskell.
To that end...
What's going on here? I'm not even calling function POP.
Michael
======================
module Data.Stack (Stack, emptyStack, isEmptyStack, push, pop, top) where
newtype Stack a = Stack [a]
emptyStack = Stack []
isEmptyStack (Stack xs) = null xs
push x (Stack xs) = Stack (x:xs)
pop (Stack (_:xs)) = Stack xs
top (Stack (x:_)) = x
======================
[michael@localhost ~]$ ghci Stack.hs
GHCi, version 6.10.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Data.Stack ( Stack.hs, interpreted )
Ok, modules loaded: Data.Stack.
*Data.Stack> let s1 = emptyStack
*Data.Stack> top (push 1 s1)
1
*Data.Stack> top (push 2 s1)
2
*Data.Stack> top (push 3 s1)
3
*Data.Stack> let s2 = pop s1
*Data.Stack> top s2
*** Exception: Stack.hs:8:0-28: Non-exhaustive patterns in function pop
*Data.Stack>
--- On Fri, 2/5/10, Casey Hawthorne