replacing the Prelude (again)
Simon Peyton-Jones
simonpj@microsoft.com
Tue, 16 Jul 2002 08:51:00 +0100
| Ambiguities in the class Num are most common, so Haskell=20
| provides another=20
| way to resolve them---with a default declaration:
| default (t1 , ... , tn)
| where n>=3D0, and each ti must be a monotype for which Num ti =
holds.=20
| ^^^^^^^^^^
| In situations where an ambiguous type is discovered, an=20
| ambiguous type=20
| variable is defaultable if at least one of its classes is=20
| a numeric class=20
| (that is, Num or a subclass of Num) and if all of its=20
| classes are defined=20
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| in the Prelude or a standard library=20
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Each defaultable variable is replaced by the first type in=20
| the default list=20
| that is an instance of all the ambiguous variable's=20
| classes. It is a=20
| static error if no such type is found."
|=20
| Do these become "whatever Num is in scope" when I use=20
| -fno-implicit-prelude, and "whatever classes from standard=20
| libraries" are in scope? If they don't then I think I'm in a pickle.
I confess that I had forgotten about this. It's not easy to=20
see what a good alternative design would be... I suppose it=20
could be "whatever Num is in scope or a subclass thereof", but
what would correspond to "defined in the Prelude or a standard lib"?
An alternative would be to drop the rule altogether with
-fno-implicit-prelude
and let all ambiguous types be defaulted with the specified list of
types. The motivation for the rules as stated is to avoid excessive=20
defaulting, which silently affects the meaning of your program.
As you say, the absence of an obvious design point means I'm=20
unlikely to fiddle just now. If a consensus emerges (and it's not
to hard to do) I'd be willing to fiddle, though.
Simon=09