Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inverse injective type families

Lets say I have an injective type family T

type family T a = b | b -> a

My first question is there an way to write:

type family T' = the inverse of T

Without having to repeat all the instances of T but in reverse.

Such that: T (X1 a (T' a)) = a

It seems like this should work, as both T and T' are injective, given one side it is mechanical to work out the other.

Anyway to write T'?

like image 513
Clinton Avatar asked Aug 14 '16 08:08

Clinton


1 Answers

With suitable extensions, one can write:

type T' b = forall a. T a ~ b => a

For example, here's an example showing that you get at least basic type compatibility with this type synonym:

type family T a = b | b -> a
type instance T Int = Bool

f :: T' Bool -> Int
f x = x
like image 102
Daniel Wagner Avatar answered Nov 13 '22 20:11

Daniel Wagner