@@ -12,12 +12,10 @@ module Data.Generics.Internal.Families.Changing
14 , PTag (..)
14 , PTag (..)
20−import GHC.TypeLits (Nat, type (-), TypeError, ErrorMessage (..))
18+import GHC.TypeLits (Nat, type (-), type (+), TypeError, ErrorMessage (..))
23 Note [Changing type parameters]
21 Note [Changing type parameters]
@@ -52,16 +50,16 @@ import GHC.TypeLits (Nat, type (-), TypeError, ErrorMessage (..))
52-- application form. In order to distinguish between applications of P and other type constructors, we use a tag, `PTag`
50-- application form. In order to distinguish between applications of P and other type constructors, we use a tag, `PTag`
53-- to fake a type constructor.
51-- to fake a type constructor.
54data PTag = PTag
52data PTag = PTag
55−type family P :: Peano -> k -> PTag -> k
53+type family P :: Nat -> k -> PTag -> k
57−type Proxied t = Proxied' t 'Z
55+type Proxied t = Proxied' t 0
59−type family Proxied' (t :: k) (next :: Peano) :: k where
57+type family Proxied' (t :: k) (next :: Nat) :: k where
60− Proxied' (t (a :: j) :: k) next = (Proxied' t ('S next)) (P next a 'PTag)
58+ Proxied' (t (a :: j) :: k) next = (Proxied' t (next + 1)) (P next a 'PTag)
61 Proxied' t _ = t
59 Proxied' t _ = t
63data Sub where
61data Sub where
64− Sub :: Peano -> k -> Sub
62+ Sub :: Nat -> k -> Sub
66type family Unify (a :: k) (b :: k) :: [Sub] where
64type family Unify (a :: k) (b :: k) :: [Sub] where
67 Unify (p n _ 'PTag) a' = '[ 'Sub n a']
65 Unify (p n _ 'PTag) a' = '[ 'Sub n a']
@@ -85,26 +83,20 @@ type family Infer (s :: *) (a' :: *) (b :: *) :: * where
86--------------------------------------------------------------------------------
84--------------------------------------------------------------------------------
88−data Peano = Z | S Peano
90−type family NatToPeano (n :: Nat) :: Peano where
92− NatToPeano n = 'S (NatToPeano (n - 1))
94-- [TODO]: work this out
86-- [TODO]: work this out
96−--type family ArgKind (t :: k) (pos :: Peano) :: * where
88+--type family ArgKind (t :: k) (pos :: Nat) :: * where
97-- ArgKind (t (a :: k)) 'Z = k
89-- ArgKind (t (a :: k)) 'Z = k
98-- ArgKind (t _) ('S pos) = ArgKind t pos
90-- ArgKind (t _) ('S pos) = ArgKind t pos
100−--type family ReplaceArg (t :: k) (pos :: Peano) (to :: ArgKind t pos) :: k where
92+--type family ReplaceArg (t :: k) (pos :: Nat) (to :: ArgKind t pos) :: k where
101-- ReplaceArg (t a) 'Z to = t to
93-- ReplaceArg (t a) 'Z to = t to
102-- ReplaceArg (t a) ('S pos) to = ReplaceArg t pos to a
94-- ReplaceArg (t a) ('S pos) to = ReplaceArg t pos to a
103-- ReplaceArg t _ _ = t
95-- ReplaceArg t _ _ = t
105−type family ReplaceArg (t :: k) (pos :: Peano) (to :: j) :: k where
97+type family ReplaceArg (t :: k) (pos :: Nat) (to :: j) :: k where
106− ReplaceArg (t a) 'Z to = t to
98+ ReplaceArg (t a) 0 to = t to
107− ReplaceArg (t a) ('S pos) to = ReplaceArg t pos to a
99+ ReplaceArg (t a) pos to = ReplaceArg t (pos - 1) to a
108 ReplaceArg t _ _ = t
100 ReplaceArg t _ _ = t
110type family ReplaceArgs (t :: k) (subs :: [Sub]) :: k where
102type family ReplaceArgs (t :: k) (subs :: [Sub]) :: k where