This occurs with Hugs 98, version 990121 beta, with -98 option.
For the source file

type Transformation a = (a, a) -> (a, a)
r :: (RealFloat a, Real b) => b -> Transformation a
r angle (x, y) = result
  where
    rangle = fromRational (toRational angle)
    result = (x * cos rangle - y * sin rangle, y * cos rangle + x * sin
rangle)
rd :: (RealFloat a, RealFrac b) => b -> Transformation a
rd degrees  = result
  where
    result = r ((degrees / 180.0) * pi)

Hugs gave the error message:

ERROR "msg.hs" (line 8): Inferred type is not general enough
*** Expression    : rd
*** Expected type : (RealFloat a, RealFrac b) => b -> Transformation a
*** Inferred type : (RealFloat a, RealFrac Double) => Double ->
Transformation a

In retrospect I can understand this message.  But at the time it was
confusing. I knew that my intended program should not lead to an inference
of type Double for the degrees parameter.  I assumed (falsely) that no more
general type could possibly be inferred from the program's expressions, and
that there was something in the expressions which required a Double
(leading to wasted effort).

My fixed program declares rd more specifically as
  rd :: (RealFloat a, RealFloat b) => b -> Transformation a
I suppose that the rules of Haskell require that the too-specific type of
Double be inferred due indirectly (and paradoxically) to the too-general
type "RealFrac b".  I can provide no specific idea for improving the error
message, but the potential for confusion is worth noting.

--
Scott Turner
[EMAIL PROTECTED]       http://www.ma.ultranet.com/~pkturner

Reply via email to