Constraint implication

Simon Peyton Jones simonpj at
Tue Jan 2 10:07:45 UTC 2018

Getting this stuff into GHC is the tricky part!
Indeed… but step 1 is to articulate a well-formed specification.  I’m not close enough to this conversation to understand all the details, let alone form a specification.  But perhaps some of you are.

I think (2) is described here:  I have been keen on this proposal for years, just lacking time to execute on it.


From: Libraries [mailto:libraries-bounces at] On Behalf Of Edward Kmett
Sent: 27 December 2017 19:18
To: Ryan Reich <ryan.reich at>
Cc: Haskell Libraries <libraries at>
Subject: Re: Constraint implication

Just a few old observations I've made from implementing these things into type systems of my own:

1.) An internal hom for the category of constraints is admissible:

(|-) :: Constraint -> Constraint -> Constraint

models entailment, and effectively brings into scope a local rule, but global instance resolution isn't lost if this is only produced from existing instances.

To your point, this is analogous to the (:-) :: Constraint -> Constraint -> * external hom for the category of constraints provided by my constraints package, but it is internal, with all of the appropriate CCC operations.

2.) Quantification over constraints is also admissible.

Neither one compromises the "thinness" of the category of constraints that provides us global coherence of instance resolution

In this case the property that if D is thin, so is [C,D]. forall here can quantify over any other kind you want.

Unfortunately, neither implemented in Haskell.

You'd need both of them to be able to talk about constraints like (forall a. Eq a |- Eq (f a)).

Together could eliminate, morally, the entire Data.Functor.Classes mess. (That said, as implemented those classes are a bit stronger than the quantified form)

3.) Constraint also admits a sum type, (\/) but it acts more like a least upper bound than an either.

It is much easier to talk about in the category of constraints using the first part above.

Given (p |- r, q |- r), (p \/ q) |- r and vice versa.

The key to keeping the category of constraints thin is that you can't case analyze on it, its more like if you look at, say, Ord [a] \/ Eq a you can get to any constraint that you could get to given the intersection of both, not using the particulars of either. e.g. its morally as powerful as Eq [a] in this case.

Getting this stuff into GHC is the tricky part!


On Wed, Dec 27, 2017 at 2:50 AM, Ryan Reich <ryan.reich at<mailto:ryan.reich at>> wrote:
The Constraint kind appears to lack an interface to an important capability that is already part of the type checker: constraint implication.  Namely, the ability to provide a witness for the statement "constraint c1 implies constraint c2" or, more importantly, "for all a, constraint (c1 a) implies constraint (c2 a)", where c1 and c2 are now constraint-valued type functions (and possibly even for constraint functions with multiple parameters).  It seems to me that this can follow the pattern of the "magic" Coercible type class and the (non-magic) Coercion data type; it provides the programmer with an analogous value to this example that can be obtained in apparently no other way.

Libraries mailing list
Libraries at<mailto:Libraries at><>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list