defaults

Simon Peyton-Jones simonpj at microsoft.com
Tue Nov 21 07:09:57 EST 2006


I think this thread is discussing your proposal 2, ignoring 1.

|   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.

Ah, that's the example I was trying to get at.  OK, so your rule is that both must give the same answer. Fine.

| > 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.

Delicate, this.  Suppose you had
        (Eq a, Foo a b, Num b)
If I start with (Eq a) I might choose Integer.  But if I start with Num b, I might choose default b=Float.  Suppose I have
        instance Fractional a => Foo a Float
Now I simplify (Foo a Float) to get Fractional a, and now I should choose a=Float.

Not very confluent.  Tricky

Simon


More information about the Haskell-prime mailing list