15 Apr
2002
15 Apr
'02
10:25 a.m.
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