Sven,

You've already heard from nhc, hbc, and ghc, so here's the
perspective from Hugs-land to complete your set.

| What is the rationale for the second condition, i.e. why is no
| defaulting done when a user-defined class is involved? Example:

Defaulting is one of those places where Haskell makes an
uncomfortable compromise between theory and practice.
>From a theoretical standpoint (e.g., providing a coherent
semantics for programs using type classes), there is no
justification at all for defaulting.  It is a wart in the
language design that lets a compiler make choices---and
significant ones too, because the can change the
semantics---without direct involvement from the programmer.
But, in practice, the overloading of numeric literals makes
it hard to get by without some defaults around.  This is
especially true in an interactive environment like Hugs,
where people expect to be able to type in 1+1 and get 2,
instead of some bizarre error message about unresolved
overloading.

So the rules for defaulting were designed to try and limit
the number of times that defaulting would be used, but
still allow it to kick in for the most common 1+1-style cases.
You could drop the restriction that you've mentioned.  You
could drop the first condition too that requires at least
one numeric class.  This wouldn't fundamentally break
anything.  It would just mean that the defaulting mechanism
kicks in more frequently, quietly making more decisions about
the semantics that it assigns to your programs.  Note that
the compilers have to do extra work to check these conditions;
it would be easy just to skip those checks if you wanted the
more liberal policy.

One day, there might be a better alternative to defaulting
that gives programmers much more control, and isn't just
restricted to numeric types (anyone for default monads?).
In the meantime, I prefer to use a compiler that enforces
the checks specified in the Haskell report, and so limits
the scope for defaulting in my programs.  It's true that,
once in a while, I have to work a little harder to specify
which instance is intended.  But I'm also grateful for the
opportunity that it gives me to participate more fully in
choosing the intended semantics for my program.

All the best,
Mark

Reply via email to