defaults
Simon Marlow
simonmar at microsoft.com
Thu Jan 4 11:15:45 EST 2007
haskell-prime-bounces at haskell.org wrote:
> Simon Peyton-Jones <simonpj at microsoft.com> writes:
>
>>> 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.
Is your proposal supposed to be backwards compatible with Haskell 98 for programs that don't have default declarations? If so, then I offer a counter example:
toRational pi
will default pi to Double in Haskell 98, but will be an error under your proposal, because the two constraints (Real and Floating) disagree on the default.
dflt.hs:3:7:
Warning: Defaulting the following constraint(s) to type `Double'
`Real a' arising from use of `toRational' at dflt.hs:3:7-19
`Floating a' arising from use of `pi' at dflt.hs:3:18-19
In the expression: toRational pi
In the definition of `test': test = toRational pi
You can generate more examples using Enum/Fractional combinations, but it's dubious whether Float & Double should be instances of Enum anyway.
Cheers,
Simon
More information about the Haskell-prime
mailing list