typing question

Tom Pledger Tom.Pledger@peace.com
Mon, 14 May 2001 14:35:14 +1200


Ben writes:
 :
 | (@@)   :: (Num a) => Polynomial a -> a -> a
 :
 | the following doesn't work,
 | [ f @@ g | f <- poly, g <- poly, f /= g ]
 | where poly is a list of polynomials gives me,
 | 
 | *** Expression     : f @@ g
 | *** Term           : f
 | *** Type           : Polynomial Integer
 | *** Does not match : Polynomial (Polynomial Integer)
 | 
 | so my question boils down to, how do I tell hugs/Haskell that
 | Polynomials over Polynomials of Integers are just Polynomials of
 | Integers or at least that this kind of composition is ok?

Your definition of (@@) looks OK.  The only problem is that you've
applied it to two arguments of the same type (f, g :: Polynomial
Integer), which don't unify with the parameter types (Polynomial a and
a).  Hugs has compared the type of the second parameter (a) with the
type of the second argument (Polynomial Integer), and applied the Most
General Unifier (the substitution of Polynomial Integer for a).  The
details of the error message refer to what happened when it compared
the types of the first argument and the first parameter.

It's worth checking whether [ f @@ g | f <- poly, g <- poly, f /= g ]
really means what you intended.