Malcolm.Wallace at cs.york.ac.uk
Mon Nov 20 13:41:45 EST 2006
Simon Peyton-Jones <simonpj at microsoft.com> wrote:
> remember that defaulting does not happen class-by-class at the moment.
Yes, and this is exactly the point of the proposal (#2). It makes sense
(to me at least) to change the rules so that defaulting happens
per-class. At the moment, it _can_ occur for any class, provided only
that the type is _also_ constrained to be an instance of Num. It is a
very strange rule, and one that I guess very few people understand
fully, yet I hope to show that one can subsume it entirely by
introducing a different but more general rule, that is easier to
> If you have
> (Eq a, Fractional a)
> where 'a' is unconstrained, the current rules pick the first type T in
> the defaulting list that satisfies all the constraints (Eq T, Fractional T).
> I don't know what would that would mean if Eq had a different
> defaulting list than Fractional, as you propose.
Well, for one thing I don't like the idea of a "list" of potential
defaults. My suggestion is that there should be a single default type
per class. If more than one class is involved, then either their
defaults should agree, or only one of them in fact declares a default.
I claim that this would be sufficient for every extant use case. But I
would quite like to have some evidence to back up this claim! If anyone
actually uses explicit defaults in their programs, I would be interested
in seeing some real data on this. Feel free to submit such example
decls to my email address. I suspect that almost no-one uses defaults
except for the original motivating case of literal numbers. If so, then
even quite a big change in this area would hurt very few people, provided it
was backward compatible with the literal number thing.
> Another issue that Haskell' needs to address is what defaulting means
> when you have multi-parameter type classes.
Yes, I was going to mention that myself on the wiki, but it slipped my
mind again. So here is one idea. If you have a single default type per
class in the SPTC scenario, then you would have a single default
_relation_ of types in the MPTC case. The default decl could be made to
look rather like an instance decl:
default Num Integer
default Fractional Double
class Dual d c where ...
default Dual Binary [Bool]
except, unlike instances, you are permitted only one of them.
More information about the Haskell-prime