help need

Arjan van IJzendoorn afie@cs.uu.nl
Mon, 15 Apr 2002 12:25:24 +0200


Hi Benny,


> instance (Float a) => Num (Poly a) where
>                    x + y = addPoly x y
> I got the "Cannot use type synonym in instance head" error message when I
was trying to
> compile the above code. Can you tell me why and how to solve it?

Unfortunately, you can not instantiate a class with a type synonym. The
solution is to make a data type:

data Poly = Poly [Float]
  deriving (Eq, Show)

instance Num Poly where
   (Poly xs) + (Poly ys) = Poly (zipWith (+) xs ys)

Note: to be instance of Num a type first has to be instance of Eq and Show

Greetings, Arjan