
Simon Peyton-Jones
| My suggestion is that there should be a single default type | per class.
Ah, I missed that.
I suppose, because the proposed new rule is so simple and short, it is rather easy to miss its implications, especially if you are used to thinking in terms of the existing more complicated rule.
Suppose I have default Eq Integer default Fractional Float and I have (Eq a, Fractional a). Does 'a' resolve to Integer or to Float? Perhaps a few examples on the proposal page would be useful for readers?
The proposed rule is that defaulting applies *after* simplification of the context. So, although you initially infer (Eq a, Fractional a) => a but after simplification, this becomes (Fractional a) => a so there is a single class to be defaulted, and Float is chosen. Here are some more examples. default Ord Integer default Fractional Float (Ord a, Fractional a) => a --> static error, because Ord is not a superclass of Fractional, so the context does not simplify, and the default types disagree. default Bounded Int default Ord Int (Ord a, Bounded a) => a --> default is Int, because even though the context does not simplify, the classes involved do agree on which default to choose. default Bounded Int default Ord Int (Ord a, Bounded a, Show a) => a --> default is Int, same as above, except for the extra constraint Show a. There is no default declared for Show, so the remaining context is used to make the choice. (Show a, Read a) => a --> static error, because there are no defaults declared for any of the classes involved. Regards, Malcolm