constraints icon indicating copy to clipboard operation
constraints copied to clipboard

Combining constraints

Open Icelandjack opened this issue 7 years ago • 6 comments

This package could provide various Constraintbuilding 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))

Icelandjack avatar Mar 01 '17 12:03 Icelandjack

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.

Icelandjack avatar Mar 01 '17 12:03 Icelandjack

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.

ekmett avatar Apr 09 '17 06:04 ekmett

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

infinity0 avatar May 31 '20 10:05 infinity0

FWIW, the trivial-constraint library defines empty constraints (up to arity 9) here.

RyanGlScott avatar May 31 '20 10:05 RyanGlScott

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

infinity0 avatar May 31 '20 11:05 infinity0

type-combinators is yet another package that defines a null constraint - this one, of arity 0.

infinity0 avatar May 31 '20 11:05 infinity0