Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Before I go back to ML out of frustration

Name: Anonymous 2010-02-28 4:31

Does anyone why this HASKAL code won't compile?


data Stack a = MkStack a (Stack a) | Null

push :: a -> Stack a -> Stack a
push a stack = MkStack a stack

pop :: Stack a -> Stack a
pop Null = Null
pop (MkStack a stacks) = stacks

instance Eq (Stack a) where 
  Null == Null = True
  Null == (MkStack _1 _2) = False
  (MkStack _1 _2) == Null = False
  (MkStack x xs) == (MkStack y ys) = (x == y) && (xs == ys)


gives me


\home\anus\haskal\peyote-joints.hs:14:38:
    Could not deduce (Eq a) from the context (Eq (Stack a))
      arising from a use of `==' at C:\stack.hs:14:38-43
    Possible fix: add (Eq a) to the context of the instance declaration
    In the first argument of `(&&)', namely `(x == y)'
    In the expression: (x == y) && (xs == ys)
    In the definition of `==':
        (MkStack x xs) == (MkStack y ys) = (x == y) && (xs == ys)


I don't see any other opportunity to "clear it up" using extra annotations or whatnot, so...

Name: Anonymous 2010-02-28 11:39

>>10
It works for me. Apparently your type constructor is fucked. Poast the whole file.

Also you can drop the last parens.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List