[Haskell-cafe] type-level integers, type-level operators, and most specific overlapping instance

TP paratribulations at free.fr
Sun Sep 22 17:07:59 CEST 2013


TP wrote:

> But I have still a question: is the behavior of GHC correct in the example
> of my initial post?

See here:

http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/type-class-extensions.html#instance-overlap

"""
When matching, GHC takes no account of the context of the instance 
declaration (context1 etc). GHC's default behaviour is that exactly one 
instance must match the constraint it is trying to resolve.
"""

My misunderstanding came from a confusion between a "context" and a 
"constraint". The context is what is before the =>, and the constraint is 
what is after, i.e. the main part of the instance declaration.

This is the reason why my context using an inequality test on type-level 
integers was not taken into account: if I understand well there must be only 
one instance that matches the constraint, independently from the contexts, 
before GHC checks that the instance context is indeed respected.

The OverlappingInstances option only helps to have only one matching 
instance (independently from the contexts): if several instances match, but 
there is a more specific one, GHC selects this one and then checks the 
corresponding instance context.

Thanks,

TP




More information about the Haskell-Cafe mailing list