[Haskell-cafe] Stack ADT?

Sebastian Fischer sebf at informatik.uni-kiel.de
Thu Feb 4 12:16:19 EST 2010


On Feb 4, 2010, at 6:07 PM, michael rice wrote:

> Can't find a Stack datatype on Hoogle? Where should I look?

Could not find one on Hackage either. Probably because its so easy to  
handcraft your own:

     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

I saw such stacks in Haskell only for educational purposes. Usually,  
people seem to use lists directly.

Sebastian


-- 
Underestimating the novelty of the future is a time-honored tradition.
(D.G.)





More information about the Haskell-Cafe mailing list