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

TP paratribulations at free.fr
Sun Sep 22 18:07:34 CEST 2013

adam vogt wrote:

> I think context and constraint mean the same thing. The haskell report
> uses the word context for
> <http://www.haskell.org/onlinereport/decls.html> for the whole list
> and constraint for one part of that list (Eq a). With the extension
> -XConstraintKinds both of those are called Constraint. In other words:
>> instance Context => InstanceHead
>> instance (Constraint, Constraint2) => InstanceHead

This is indeed more in accordance with what I believe to be a context or a 
constraint. But, it seems that in this page


the vocabulary is different:

  instance context1 => C Int a     where ...  -- (A)
  instance context2 => C a   Bool  where ...  -- (B)
  instance context3 => C Int [a]   where ...  -- (C)
  instance context4 => C Int [Int] where ...  -- (D)

The instances (A) and (B) match the constraint C Int Bool, but (C) and (D) 
do not. When matching, GHC takes no account of the context of the instance 
declaration (context1 etc).


The -XOverlappingInstances flag instructs GHC to allow more than one 
instance to match, provided there is a most specific one. For example, the 
constraint C Int [Int] matches instances (A), (C) and (D), but the last is 
more specific, and hence is chosen. If there is no most-specific match, the 
program is rejected. 

So, what do I miss? Isn't the vocabulary different here?
And I do not understand what is written if I take your definition (which is 
indeed the definition in the Haskell report).

Thanks in advance,


More information about the Haskell-Cafe mailing list