Help need "Cannot use type synonym in instance head"

Jon Cast jcast@ou.edu
Sun, 14 Apr 2002 00:05:52 -0500


Benny <neon_2001@hotmail.com> writes:

> type Poly = [Float]

> addPoly::Poly->Poly->Poly
> addPoly x y = zipWith (+) x y

> instance (Float a) => Num (Poly a) where
>               (+) = addPoly

> I got the error message "Cannot use type synonym in instance head"
> when I was trying to compile the codes above. Can anyone tell me why
> and how to solve it?

You can either substitute in the type synonym:

> instance Num [Float] where
>	   (+) = addPoly

Or change Poly to newtype:

> newtype Poly = Poly [Float]

> addPoly::Poly->Poly->Poly
> addPoly (Poly x) (Poly y) = Poly (zipWith (+) x y)

HTH

> Cheers

> Benny

Jon Cast