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 6:17

Riddle this!

sumstack :: (Num a) => Stack a -> a                        
sumstack Null = 0
sumstack (MkStack x xs) = x + (sumstack xs)

to

peyote-joints.hs:1:25:
    `Stack' is not applied to enough type arguments
    Expected kind `?', but `Stack' has kind `* -> *'
    In the data type declaration for `Stack'
Failed, modules loaded: none.

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