[Haskell-cafe] the overlapping instance that wasn't?

wren ng thornton wren at freegeek.org
Wed Aug 25 01:21:57 EDT 2010


On 8/24/10 5:12 PM, C. McCann wrote:
> The problem is that instance selection doesn't work the (obvious,
> seemingly-sensible) way you thought it did. In short, instance
> contexts are only examined after the fact;
> [...]
> The reason it works this way has to do with the nature of type classes
> being "open".

Not necessarily. You can implement instance resolution just fine by 
using a backtracking search. There's nothing wrong with verifying the 
constraints before committing to an instance that unifies the head; It's 
a perfectly sensible way to do things.

Unfortunately this makes instance resolution undecidable, and makes it 
so that determining whether instances "overlap" is no longer a lexical 
property of the code. But, well, you get the power you pay for. 
Apparently we Haskellers don't like to pay for much since we use a 
greedy algorithm for instance resolution :)

-- 
Live well,
~wren


More information about the Haskell-Cafe mailing list