heliaxdev / extensible-data

Generate the boilerplate for the Trees That Grow pattern
https://heliaxdev.github.io/extensible-data/Extensible.html
5 stars 0 forks source link

Apply FooAll to the right number of arguments when generating instances #13

Closed andy-morris closed 4 years ago

andy-morris commented 4 years ago

Edited to add extra context:

Given the input

data Threither a b c = Left a | Mid b | Right c deriving Eq
data Foo = F (Threither String Int Bool) deriving Eq

the output contains an instance

--                 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
deriving instance (ThreitherAll Eq ext, FooAll Eq ext) => Eq (Foo' ext)

with a context that is total nonsense.


This is harder than I thought it would be yesterday: an instance like

deriving instance (FooAll Eq a) => Eq Bar

makes no sense: what is the a in the context? Does it mean (forall a. FooAll Eq a)? That might work but it requires QuantifiedConstraints and anyway there must be a better solution.

Maybe each datatype has to go through its constructors, see how everything else in the group is being used, and collect all the constraints that arise?