[Haskell-cafe] type-level integers, type-level operators, and most specific overlapping instance
paratribulations at free.fr
Sun Sep 22 17:07:59 CEST 2013
> But I have still a question: is the behavior of GHC correct in the example
> of my initial post?
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.
More information about the Haskell-Cafe