confusion

Matt Harden matth@mindspring.com
Sun, 13 May 2001 20:21:29 -0500


Ben wrote:
> 
> Dear hugs maintainers,

Well, I'm not a hugs maintainer, but I'll give it my best shot...

What you report is the correct behavior of the Haskell type system, not
a hugs bug.

> ...
> (@@)   :: (Num a) => Polynomial a -> a -> a
> ...
> 
> set   = [0..t]
> poly = [ toPolynomial [x1,x2] | x1<-set, x2<-set ]
> compo = [ f@@g | f <- poly, g <- poly, f /= g ]
> 
> However this doesn't work and fails with an error:
> 
> ERROR "/home/brain/school/current/poly.hs" (line 7): Type error in application
> *** Expression     : f @@ g
> *** Term           : f
> *** Type           : Polynomial Integer
> *** Does not match : Polynomial (Polynomial Integer)

To understand this error, think carefully about the types of the
operations involved.  Use the :t command to get the types of (@@), poly,
and (/+).  Here they all are:

Polynomial> :t (@@)
(@@) :: (Num a) => Polynomial a -> a -> a
Polynomial> :t poly
poly :: [Polynomial Integer]
Polynomial> :t (/=)
(/=) :: Eq a => a -> a -> Bool

Now consider the types of f and g in the definition of compo.  Are they
the same, or different?  You should understand then why (f@@g) is not
well-typed.  I would suggest that the composition operator you seek is
similar to (@@), but not the same, because it's type would be different.

I hope that helps.

Matt