constraints
constraints copied to clipboard
Combining constraints
This package could provide various Constraint
building blocks, names / fixity from Control.Constraint.Combine
class (c a, d a) => (c :&: d) a
instance (c a, d a) => (c :&: d) a
infixl 7 :&:
Same as :&:
type c `And` d = c :&: d
infixl 7 `And`
And the unit of :&:
, the empty constraint
class Empty a
instance Empty a
It would be good to have a standardised place for these / name / fixity (especially when I start needing to define instances of them, as for instance (HasSuperClasses c, HasSuperClasses d) => HasSuperClasses (c :&: d)
)
Also things like
class f (g x) => (f `Compose` g) x
instance f (g x) => (f `Compose` g) x
infixr 9 `Compose`
taken from Compose
.
I rather deliberately avoided moving up to higher kinds in this package because there isn't a good way to know when to stop and it actively gets in the way of better packages using this as a building block.
Could we at least define the empty constraints here? I just found out about exists
from this ticket, it turns out I did a similar thing with And
in another library I wrote but in a different way (using type families with singletons defun symbols), but the common shared thing was that we both needed an empty constraint class.
GHC goes up to a 62-tuple on my machine (I guess because it's 64-bit), but I suppose stopping at 5 or 6 parameters for this series of typeclasses would be sufficient for now. My concrete use-case has 2 parameters, for manipulating generic constraints over a key-value store.
I've also had to define this explicitly every time when trying out new ideas, this gets tiring.
class Empty1 a
instance Empty1 a
class Empty2 a b
instance Empty2 a b
-- etc
FWIW, the trivial-constraint
library defines empty constraints (up to arity 9) here.
Thanks! That seems suitable, fully-featured, with no extra cruft, and well-maintained for what it does. I still think it would be nice to merge that with this library, to make it much easier to find & visible, so that more people would standardise upon it. My previous google and hoogle searches for "null constraint" "empty constraint" didn't find it, and exists
is not using it either. It only has two reverse-dependencies
type-combinators is yet another package that defines a null constraint - this one, of arity 0.