I've got a "linear" type family, i.e. of the form
type family Foo a
type instance Foo T1 = T2
type instance Foo T2 = T3
...
type instance Foo T9 = T10
In my particualr use-case, it is very convenient to define the "reverse" family FooRev
and then enforce the constraint (FooRev (Foo x) ~ x)
:
type family FooRev a
type instance FooRev T10 = T9
type instance FooRev T9 = T8
...
type instance FooRev T2 = T1
The reverse family allows GHC to infer many types that would otherwise be ambiguous due to non-injectivity. It is essentially the same idea that was proposed here. This solution works pretty well, but it is annoying, programatic, and error-prone to have to define a "reverse" type family by listing out all the cases. Is there a more generic way to define the reverse of a linear family such as Foo
?
data
families instead somehow, which are known injective. Not sure if it fits your problem. – luquimap swap
, and derive both type families from the list. – chiTi
are all typeBar a b c
where the type parameters change. That won't fit into a data family, will it? – crockeea