[Haskell-cafe] How to expose if a constraint is satisfiable

Clinton Mead clintonmead at gmail.com
Mon May 7 04:57:40 UTC 2018

It's occurred to me that one could write a class C t which is satisfied
whenever (A t) or (B t) is satisfied like so:


data Satisfied

type family IsSatisfiable :: Constraint -> Type

class A t

class B t

class C' t ta tb

instance A t => C' t Satisfied tb where

instance B t => C' t ta Satisfied where

instance (A t, B t) => C' t Satisfied Satisfied where

class C' t ( IsSatisfiable (A t)) ( IsSatisfiable (B t)) => C t


We may need overlapping instances (with all the caveats that come with it)
but it should be fine otherwise.

"IsSatisfiable" here is defined as follows:

IsSatisfiable c = Satisfied -- (if c is satisfiable)
IsSatisfiable c = IsSatisfiable c -- (if c is not satisfiable)

That's all that's needed. And it seems to be a reasonable type function. I
note classes are open, so perhaps it could be dangerous to state that a
constraint is not satisfiable (because it might be in another part of a
program) but simply not reducing if we can't satisfy the constraint locally
should be fine I think. At worst we'll get a compile error, but we
shouldn't get inconsistent types.

Is there anyway to implement this type function, or alternatively an
approach which allows this type of "inherit from two classes" idea?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180507/b75a81e1/attachment.html>

More information about the Haskell-Cafe mailing list