[Haskell-beginners] Re: Problem implementing a stack

Maciej Piechotka uzytkownik2 at gmail.com
Sun Dec 13 05:56:05 EST 2009

>     data Stack a = Top (Stack a) | Layers [a] deriving (Show)

Sorry I'm asking - but why Stack is either a 'Stack or List' - shouldn't
it be either plain list or list-lile structure:

data Stack a = EmptyStack | Stack a (Stack a)
(unless you're training 'data' I'd say newtype Stack a = Stack [a])

Otherwise Top (Top (Layers [])) is a stack (yet it does not fit into
rest of the functions) or even fix Top (i.e. Top (Top (Top (Top (...)
Unless it have some reason of course.


More information about the Beginners mailing list