
On Thu, 4 Feb 2010 09:07:28 -0800 (PST), you wrote:
Can't find a Stack datatype on Hoogle? Where should I look?
Michael
From "Algorithms: a functional programming approach" Second edition Fethi Rabhi Guy Lapalme To be more complete. module Stack(Stack,push,pop,top,emptyStack,stackEmpty) where push :: a-> Stack a -> Stack a pop :: Stack a -> Stack a top :: Stack a -> a emptyStack :: Stack a stackEmpty :: Stack a -> Bool data Stack a = EmptyStk | Stk a (Stack a) push x s = Stk x s pop EmptyStk = error "pop from an empty stack" pop (Stk _ s) = s top EmptyStk = error "top from an empty stack" top (Stk x _) = x emptyStack = EmptyStk stackEmpty EmptyStk = True stackEmpty _ = False newtype Stack a = Stk [a] push x (Stk xs) = Stk (x:xs) pop (Stk []) = error "pop from an empty stack" pop (Stk (_:xs)) = Stk xs top (Stk []) = error "top from an empty stack" top (Stk (x:_)) = x emptyStack = Stk [] stackEmpty (Stk []) = True stackEmpty (Stk _ ) = False -- Regards, Casey