Understanding constraints-extras - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Sridhar Ratnakumar

Just started to read and understand how Data.Constraint.Extras is used/works (it used in aeson-gadt-th that derives JSON automatically for GADTs). Someone recently opened a PR to add module documentation, which seems pretty useful: https://github.com/obsidiansystems/constraints-extras/blob/develop/src/Data/Constraint/Extras.hs

Convenience functions and template haskell for working with constraints - obsidiansystems/constraints-extras
Sridhar Ratnakumar

Note that this library is based on ekmett's Data.Constraint

Sridhar Ratnakumar

This trips me up:

type Has (c :: k -> Constraint) f = (ArgDict c f, ConstraintsFor f c)

ArgDict is a class, not a type. How can it be in the RHS of a type declaration?

Sridhar Ratnakumar

Oh, right. Has is not of kind Type (which is what a regular type declaration would get you), but of Constraint. Specifically, it is referred to as "constraint synonym" (which is a kind of type synonym). This is enabled by the XConstraintKinds extension.

Sridhar Ratnakumar

Correction: aeson-gadt does not use the constraint libraries. Though the two are usually used in conjunction, especially when using libraries like dependent-sum

Template Haskell for generating ToJSON and FromJSON instances for GADTs - obsidiansystems/aeson-gadt-th
Sridhar Ratnakumar

I'm yet to revisit this and write a short tutorial on the topic (got too much on plate) but for now, this PR might of be interest: it improves the documentation of dependent-sum with helpful pointers to where ArgDict from constraints-extras fits in: https://github.com/mokus0/dependent-sum/pull/42/files

mpickering on IRC suggested that a pointer to deriveArgDict would be useful. I also tried to clarify the rest of the haddock for DSum. @mpickering: Is this clear enough, do you think, or should the...