[Haskell-beginners] Problem implementing a stack
shujinw at gmail.com
Tue Dec 8 20:17:25 EST 2009
Hello. I'm implement data structures (a stack, here) to get familiar with
Haskell. It's not going very well. I have the following code...
data Stack a = Top (Stack a) | Layers [a] deriving (Show)
stack :: Stack a
stack = Top (Layers )
push :: Stack a -> a -> Stack a
push (Top (Layers ls)) value = Top (Layers (value:ls))
And I run the following in ghci...
Prelude> :l test
[1 of 1] Compiling Main ( test.hs, interpreted )
Ok, modules loaded: Main.
*Main> push stack 4
Top (Layers )
*Main> let st = stack
*Main> push st 4
The output of the last command never resolves. I have to kill it. Might
anyone have an idea why the push function is failing with st, but not
I know there are other stack implementations that work, but I really
want to know what's going on here.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners