[Haskell-beginners] Checking if a Stack is Empty
amindfv at gmail.com
Tue Mar 12 19:13:00 CET 2013
This chapter of Real World Haskell exactly explains the problem you're having:
(The short answer is, you need an `Eq` instance for the data type
you've created (`Stack`). You can just use `deriving`.)
On Tue, Mar 12, 2013 at 7:48 AM, doaltan <doaltan at yahoo.co.uk> wrote:
> I have this stack data structure :
> data Stack = Empty | Element Char Stack deriving Show
> I want to check if it is equal to "Empty"
> When I try something like this :
> "a = Empty" or "a = (Empty)" in a haskell file and then write this on ghci :
> "a = Empty"
> I get this :
> No instance for (Eq Stack)
> arising from a use of `==' at <interactive>:1:0-11
> Possible fix: add an instance declaration for (Eq Stack)
> In the expression: a == (Empty)
> In the definition of `it': it = a == (Empty)
> I don't know how to fix this. Can you help me so that I can check if a stack
> is Empty without getting this error?
> Thank you.
> Beginners mailing list
> Beginners at haskell.org
More information about the Beginners