[Haskell-cafe] Re: coherence when overlapping?

Aaron Denney wnoise at ofb.net
Thu Apr 13 16:57:51 EDT 2006


On 2006-04-13, Martin Sulzmann <sulzmann at comp.nus.edu.sg> wrote:
>
> I believe that GHC's overlapping instance extensions
> effectively uses inequalities.
>
> Why do you think that 'inequalities' model 'best-fit'?
>
> instance C Int      -- (1)
> instance C a        -- (2)
>
> under a 'best-fit' instance reduction strategy
> we would resolve C a by using (2).
>
> 'best-fit' should be very easy to implement.
> Simply order instances (resulting CHRs) in an appropriate
> 'best-fit' order.
>
> In case of
>
> instance C Int   
> instance a =!=Int | C a    (2')
>
> we can't reduce C a (because we can't satisfy a=!=Int)
>
> Notice that (2') translates to
>
> rule C a | a =!=Int <==> True
>
> I think it's better to write a =!=Int not as part of the instance
> context but write it as a guard constraint.
>
> I don't think there's any issue for an implementation (either using
> 'best-fit' or explicit inequalities). The hard part is to establish
> inference properties such as completeness etc.
>

This best-fit is essentially what people doing multi-method dispatch
want.  It turns out to not be as trivial as one would hope.

-- 
Aaron Denney
-><-



More information about the Haskell-Cafe mailing list