@@ -67,74 +67,87 @@ instance Splittable as bs cs => Splittable (a ': as) bs (a ': cs) where
67-- * Convert tuples to/from HLists
67-- * Convert tuples to/from HLists
69class ListTuple (tuple :: Type) (as :: [Type]) | as -> tuple where
69class ListTuple (tuple :: Type) (as :: [Type]) | as -> tuple where
70+ type ListToTuple as :: Type
70 tupleToList :: tuple -> HList as
71 tupleToList :: tuple -> HList as
71 listToTuple :: HList as -> tuple
72 listToTuple :: HList as -> tuple
73instance ListTuple () '[] where
74instance ListTuple () '[] where
75+ type ListToTuple '[] = ()
74 tupleToList _ = Nil
76 tupleToList _ = Nil
75 listToTuple _ = ()
77 listToTuple _ = ()
77instance ListTuple a '[a] where
79instance ListTuple a '[a] where
80+ type ListToTuple '[a] = a
78 tupleToList a
81 tupleToList a
79 = a :> Nil
82 = a :> Nil
80 listToTuple (a :> Nil)
83 listToTuple (a :> Nil)
83instance ListTuple (a, b) '[a, b] where
86instance ListTuple (a, b) '[a, b] where
87+ type ListToTuple '[a, b] = (a, b)
84 tupleToList (a, b)
88 tupleToList (a, b)
85 = a :> b :> Nil
89 = a :> b :> Nil
86 listToTuple (a :> b :> Nil)
90 listToTuple (a :> b :> Nil)
89instance ListTuple (a, b, c) '[a, b, c] where
93instance ListTuple (a, b, c) '[a, b, c] where
94+ type ListToTuple '[a, b, c] = (a, b, c)
90 tupleToList (a, b, c)
95 tupleToList (a, b, c)
91 = a :> b :> c :> Nil
96 = a :> b :> c :> Nil
92 listToTuple (a :> b :> c :> Nil)
97 listToTuple (a :> b :> c :> Nil)
93 = (a, b, c)
98 = (a, b, c)
95instance ListTuple (a, b, c, d) '[a, b, c, d] where
100instance ListTuple (a, b, c, d) '[a, b, c, d] where
101+ type ListToTuple '[a, b, c, d] = (a, b, c, d)
96 tupleToList (a, b, c, d)
102 tupleToList (a, b, c, d)
97 = a :> b :> c :> d:> Nil
103 = a :> b :> c :> d:> Nil
98 listToTuple (a :> b :> c :> d :> Nil)
104 listToTuple (a :> b :> c :> d :> Nil)
99 = (a, b, c, d)
105 = (a, b, c, d)
101instance ListTuple (a, b, c, d, e) '[a, b, c, d, e] where
107instance ListTuple (a, b, c, d, e) '[a, b, c, d, e] where
108+ type ListToTuple '[a, b, c, d, e] = (a, b, c, d, e)
102 tupleToList (a, b, c, d, e)
109 tupleToList (a, b, c, d, e)
103 = a :> b :> c :> d:> e :> Nil
110 = a :> b :> c :> d:> e :> Nil
104 listToTuple (a :> b :> c :> d :> e :> Nil)
111 listToTuple (a :> b :> c :> d :> e :> Nil)
105 = (a, b, c, d, e)
112 = (a, b, c, d, e)
107instance ListTuple (a, b, c, d, e, f) '[a, b, c, d, e, f] where
114instance ListTuple (a, b, c, d, e, f) '[a, b, c, d, e, f] where
115+ type ListToTuple '[a, b, c, d, e, f] = (a, b, c, d, e, f)
108 tupleToList (a, b, c, d, e, f)
116 tupleToList (a, b, c, d, e, f)
109 = a :> b :> c :> d:> e :> f :> Nil
117 = a :> b :> c :> d:> e :> f :> Nil
110 listToTuple (a :> b :> c :> d :> e :> f :> Nil)
118 listToTuple (a :> b :> c :> d :> e :> f :> Nil)
111 = (a, b, c, d, e, f)
119 = (a, b, c, d, e, f)
113instance ListTuple (a, b, c, d, e, f, g) '[a, b, c, d, e, f, g] where
121instance ListTuple (a, b, c, d, e, f, g) '[a, b, c, d, e, f, g] where
122+ type ListToTuple '[a, b, c, d, e, f, g] = (a, b, c, d, e, f, g)
114 tupleToList (a, b, c, d, e, f, g)
123 tupleToList (a, b, c, d, e, f, g)
115 = a :> b :> c :> d:> e :> f :> g :> Nil
124 = a :> b :> c :> d:> e :> f :> g :> Nil
116 listToTuple (a :> b :> c :> d :> e :> f :> g :> Nil)
125 listToTuple (a :> b :> c :> d :> e :> f :> g :> Nil)
117 = (a, b, c, d, e, f, g)
126 = (a, b, c, d, e, f, g)
119instance ListTuple (a, b, c, d, e, f, g, h) '[a, b, c, d, e, f, g, h] where
128instance ListTuple (a, b, c, d, e, f, g, h) '[a, b, c, d, e, f, g, h] where
129+ type ListToTuple '[a, b, c, d, e, f, g, h] = (a, b, c, d, e, f, g, h)
120 tupleToList (a, b, c, d, e, f, g, h)
130 tupleToList (a, b, c, d, e, f, g, h)
121 = a :> b :> c :> d:> e :> f :> g :> h :> Nil
131 = a :> b :> c :> d:> e :> f :> g :> h :> Nil
122 listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> Nil)
132 listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> Nil)
123 = (a, b, c, d, e, f, g, h)
133 = (a, b, c, d, e, f, g, h)
125instance ListTuple (a, b, c, d, e, f, g, h, j) '[a, b, c, d, e, f, g, h, j] where
135instance ListTuple (a, b, c, d, e, f, g, h, j) '[a, b, c, d, e, f, g, h, j] where
136+ type ListToTuple '[a, b, c, d, e, f, g, h, j] = (a, b, c, d, e, f, g, h, j)
126 tupleToList (a, b, c, d, e, f, g, h, j)
137 tupleToList (a, b, c, d, e, f, g, h, j)
127 = a :> b :> c :> d:> e :> f :> g :> h :> j :> Nil
138 = a :> b :> c :> d:> e :> f :> g :> h :> j :> Nil
128 listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> Nil)
139 listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> Nil)
129 = (a, b, c, d, e, f, g, h, j)
140 = (a, b, c, d, e, f, g, h, j)
131instance ListTuple (a, b, c, d, e, f, g, h, j, k) '[a, b, c, d, e, f, g, h, j, k] where
142instance ListTuple (a, b, c, d, e, f, g, h, j, k) '[a, b, c, d, e, f, g, h, j, k] where
143+ type ListToTuple '[a, b, c, d, e, f, g, h, j, k] = (a, b, c, d, e, f, g, h, j, k)
132 tupleToList (a, b, c, d, e, f, g, h, j, k)
144 tupleToList (a, b, c, d, e, f, g, h, j, k)
133 = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> Nil
145 = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> Nil
134 listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> Nil)
146 listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> Nil)
135 = (a, b, c, d, e, f, g, h, j, k)
147 = (a, b, c, d, e, f, g, h, j, k)
137instance ListTuple (a, b, c, d, e, f, g, h, j, k, l) '[a, b, c, d, e, f, g, h, j, k, l] where
149instance ListTuple (a, b, c, d, e, f, g, h, j, k, l) '[a, b, c, d, e, f, g, h, j, k, l] where
150+ type ListToTuple '[a, b, c, d, e, f, g, h, j, k, l] = (a, b, c, d, e, f, g, h, j, k, l)
138 tupleToList (a, b, c, d, e, f, g, h, j, k, l)
151 tupleToList (a, b, c, d, e, f, g, h, j, k, l)
139 = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> Nil
152 = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> Nil
140 listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> Nil)
153 listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> Nil)
@@ -143,6 +156,7 @@ instance ListTuple (a, b, c, d, e, f, g, h, j, k, l) '[a, b, c, d, e, f, g, h, j
143--------------------------------------------------------------------------------
156--------------------------------------------------------------------------------
145class GCollectible (f :: Type -> Type) (as :: [Type]) | f -> as where
158class GCollectible (f :: Type -> Type) (as :: [Type]) | f -> as where
159+ type GCollect f :: [Type]
146 gtoCollection :: f x -> HList as
160 gtoCollection :: f x -> HList as
147 gfromCollection :: HList as -> f x
161 gfromCollection :: HList as -> f x
@@ -152,6 +166,7 @@ instance
152 , cs ~ (as ++ bs)
166 , cs ~ (as ++ bs)
153 , Splittable as bs cs
167 , Splittable as bs cs
154 ) => GCollectible (l :*: r) cs where
168 ) => GCollectible (l :*: r) cs where
169+ type GCollect (l :*: r) = GCollect l ++ GCollect r
156 gtoCollection (l :*: r)
171 gtoCollection (l :*: r)
157 = gtoCollection l `append` gtoCollection r
172 = gtoCollection l `append` gtoCollection r
@@ -160,14 +175,17 @@ instance
160 = gfromCollection as :*: gfromCollection bs
175 = gfromCollection as :*: gfromCollection bs
161 where (as, bs) = split cs
176 where (as, bs) = split cs
163−instance GCollectible (K1 R a) '[a] where
178+instance GCollectible (Rec0 a) '[a] where
179+ type GCollect (Rec0 a) = '[a]
164 gtoCollection = (:> Nil) . unK1
180 gtoCollection = (:> Nil) . unK1
165 gfromCollection = K1 . head'
181 gfromCollection = K1 . head'
167instance GCollectible U1 '[] where
183instance GCollectible U1 '[] where
184+ type GCollect U1 = '[]
168 gtoCollection U1 = Nil
185 gtoCollection U1 = Nil
169 gfromCollection Nil = U1
186 gfromCollection Nil = U1
171instance GCollectible f as => GCollectible (M1 m meta f) as where
188instance GCollectible f as => GCollectible (M1 m meta f) as where
189+ type GCollect (M1 m meta f) = GCollect f
172 gtoCollection = gtoCollection . unM1
190 gtoCollection = gtoCollection . unM1
173 gfromCollection = M1 . gfromCollection
191 gfromCollection = M1 . gfromCollection