@@ -11,10 +11,13 @@
11module Data.Generics.Internal.Families.Changing
11module Data.Generics.Internal.Families.Changing
16−import GHC.TypeLits (TypeError, ErrorMessage (..))
20+import GHC.TypeLits (Nat, type (-), TypeError, ErrorMessage (..))
17−import Data.Type.Bool (If)
20 Note [Changing type parameters]
23 Note [Changing type parameters]
@@ -61,7 +64,8 @@ data Sub where
61 Sub :: Peano -> k -> Sub
64 Sub :: Peano -> k -> Sub
63type family Unify (a :: k) (b :: k) :: [Sub] where
66type family Unify (a :: k) (b :: k) :: [Sub] where
64− Unify (a b) a' = If (IsPTag b) '[HandleP (a b) a'] (HandleOther (a b) a')
67+ Unify (p n _ 'PTag) a' = '[ 'Sub n a']
68+ Unify (a x) (b y) = Unify x y ++ Unify a b
65 Unify a a = '[]
69 Unify a a = '[]
66 Unify a b = TypeError
70 Unify a b = TypeError
67 ( 'Text "Couldn't match type "
71 ( 'Text "Couldn't match type "
@@ -70,23 +74,6 @@ type family Unify (a :: k) (b :: k) :: [Sub] where
70 ':<>: 'ShowType b
74 ':<>: 'ShowType b
73−type family HandleP a b where
74− HandleP (p n _ 'PTag) a' = 'Sub n a'
76−type family HandleOther a b where
77− HandleOther (a x) (b y) = Unify x y ++ Unify a b
78− HandleOther a a = '[]
79− HandleOther a b = TypeError
80− ( 'Text "Couldn't match type "
86−type family IsPTag (a :: k) :: Bool where
90type family (xs :: [k]) ++ (ys :: [k]) :: [k] where
77type family (xs :: [k]) ++ (ys :: [k]) :: [k] where
91 '[] ++ ys = ys
78 '[] ++ ys = ys
92 (x ': xs) ++ ys = x ': (xs ++ ys)
79 (x ': xs) ++ ys = x ': (xs ++ ys)
@@ -100,6 +87,10 @@ type family Infer (s :: *) (a' :: *) (b :: *) :: * where
101data Peano = Z | S Peano
88data Peano = Z | S Peano
90+type family NatToPeano (n :: Nat) :: Peano where
92+ NatToPeano n = 'S (NatToPeano (n - 1))
103-- [TODO]: work this out
94-- [TODO]: work this out
105--type family ArgKind (t :: k) (pos :: Peano) :: * where
96--type family ArgKind (t :: k) (pos :: Peano) :: * where