> What's going on here? I'm not even calling function POP.
> *Data.Stack> let s2 = pop s1
> *Data.Stack> top s2
> *** Exception: Stack.hs:8:0-28: Non-exhaustive patterns in function pop

Haskell being a non strict language, does not evaluate pop s1 when you define
let s2 = pop s1.
but when you try to use s2 by evaluating "top s2" "pop s1" needs to be evaluated
leading to the error in "pop", since the definition of pop, does not
deal with the case when
the Stack is empty (Stack []).

> pop (Stack (_:xs)) = Stack xs
> top (Stack (x:_)) = x
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to