[Haskell-cafe] Haskell spec vs FlexibleInstances
Dan Doel
dan.doel at gmail.com
Tue Feb 18 20:51:15 UTC 2014
On Tue, Feb 18, 2014 at 3:40 PM, Brandon Allbery <allbery.b at gmail.com>wrote:
>
> On Tue, Feb 18, 2014 at 3:11 PM, Doug McIlroy <doug at cs.dartmouth.edu>wrote:
>
>> What potential evil motivates the prohibition of repeated type
>> parameters in an instance declaration? (Restriction removed
>> by FlexibleInstances)
>>
>
> Isn't that just related to constraints not being part of instance
> selection? (Assuming that `instance SomeClass a a` is interpreted as
> `instance (a ~ b) => SomeClass a b`, since I don't quite see how it would
> work otherwise given how instances work; the constraint is not necessarily
> obvious from looking at it. Also note that standard Haskell can't therefore
> describe this instance properly.)
>
These two instances do not actually work the same way.
instance (a ~ b) => SomeClass a b
says that any context containing 'SomeClass a b' can be reduced to a
context containing (a ~ b) instead.
instance SomeClass a a
says that a 'SomeClass a b' constraint can be discharged if we enter a
state in which the type checker _decides_ that a = b.
In a sense, the first instance can provide information, while the second
requires it. Whether there should be such a distinction is left up to the
reader.
-- Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140218/d02fa933/attachment.html>
More information about the Haskell-Cafe
mailing list