overlapping instances and constraints
claus.reinke at talk21.com
Tue Feb 28 13:54:32 EST 2006
>> Tuesday, February 28, 2006, 1:54:25 PM, you wrote:
>> CR> class NEq a b
>> CR> instance Fail a => NEq a a
>> CR> instance NEq a b
>> i think that this definition just use ad-hoc overlapping instances
>> resolution mechanism that we want to avoid :)))
I don't want to avoid it completely, I want to give it more specifics
to work with. but yes, type inequality would avoid many overlaps.
the example was just meant to demonstrate the programmers could
already specify their intention in current Haskell, by using Eq/NEq
(in instance constraints), but it wouldn't be much use as long as
current Haskell implementations ignore those intentions.
>Actually, it illustrates beautifully why ad-hoc overlapping doesn't
>work. There are two interpretations, the desired one, and one that
>just ignores the the first and uses the second for everything.
I'm not sure what you're talking about? both hugs and ghc clearly
specify that the more specific instance declaration is chosen when
overlapping instance declarations are permitted. the repeated a
makes the first declaration more specific, so both hugs and ghc
accept the attached code, and deliver the same result, as specified.
[if only that could be said for all programs, Haskell' could be
built on much safer grounds, and everybody happier:-]
overlapping resolution by choosing the most specific instance is
no more black art than pattern-matching resolution by choosing
the first match - some would say, less so.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 578 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/haskell-prime/attachments/20060228/6247820f/TypeNotEq.obj
More information about the Haskell-prime