Ian writes:
Should the following be legal or not?
data T a = F (a->a->Bool)
x = F (==)
The compilers all produce an `ambiguous overloading' error, and I am not sure
why. Everything is OK if you give a type declaration for x (x :: Eq a => T a)
or if you add an argument to x.
You are up against the dreaded monomorphism restriction which has
been discussed to death in the past. The bottom line here is that the
definition of x could either be
a) A single, specific value of type T. This would require that the
overloading of == be resolved.
b) A definition valid at all overloadings of ==. Unlike the
previous case, the program may have to build many values of type
T for x - at least one for every distinct overloading used and
very possibly more unless some sort of memoization occurs.
The monomorphism restriction states that choice a is the default for
pattern binding, choice b is the default for function binding, and
that the default can be overridden with an explicit type signature.
Perhaps the best thing would be to devise an error message which
quotes a few pages of the report and all dialogue on the mailing list
regarding monomorphism!
John