[Haskell-cafe] Can't explain this error

robert dockins robdockins at fastmail.fm
Mon Jul 11 12:15:11 EDT 2005

> Thanks for your reply,
> i just simply removed the first line and it works, but i dont understand 
> why 1/x is not Float.

It depends on the type of 'x'.  If 'x' is a Float, (1/x) will be a 
Float.   If 'x' is a Double, (1/x) will be a Double.  If 'x' is an 
Integer (1/x) will not typecheck because (/) is only defined for 
Fractional arguments, and Integer is not an element of Fractional.  In 
your case, you had constrained 'x' to be an Integer, so it requires a 
cast to perform the division and get a Float.

Removing the type signature allows the compiler to assign a more general 
type to 'x', and so it typechecks.

More information about the Haskell-Cafe mailing list