@@ -185,39 +185,41 @@ instance UnderlyingConversion BS.ByteString U.UUID where
185
185
-- Note: it turns out that GHC.Generics generates some weird
186
186
-- instances for records in the form (x :*: y) :*: z
187
187
-- and we cover them with the special HereLeft and HereRight
188
- data Where = Here | HereLeft | HereRight | HereRightThenLeft | HereTwoRights | There Where
188
+ data Where = Here | There Where
189
+ data WhereStep = StepNoMore | StepLeft | StepRight
189
190
190
191
type family Find (xs :: [k ]) (x :: k ) :: Where where
191
192
Find '[] y = TypeError ('Text " Could not find " ':<>: 'ShowType y )
192
193
Find (y ': xs ) y = 'Here
193
194
Find (x ': xs ) y = 'There (Find xs y )
194
195
195
- type family FindCon (xs :: * -> * ) (x :: Symbol ) :: [Where ] where
196
+ type family FindCon (xs :: * -> * ) (x :: Symbol ) :: [WhereStep ] where
196
197
FindCon xs x = WhenEmpty
197
198
(FindCon' '[] xs x )
198
199
(TypeError ('Text " Could not find constructor " ':<>: 'ShowType x ))
199
200
200
- -- TODO: Maybe 'Where' isn't the right thing to use here.
201
- type family FindCon' (begin :: [Where ]) (xs :: * -> * ) (x :: Symbol ) :: [Where ] where
202
- FindCon' acc (C1 ('MetaCons x p s ) f ) x = Eval (Snoc acc 'Here)
201
+ type family FindCon' (begin :: [WhereStep ]) (xs :: * -> * ) (x :: Symbol ) :: [WhereStep ] where
202
+ FindCon' acc (C1 ('MetaCons x p s ) f ) x = Eval (Snoc acc 'StepNoMore)
203
203
FindCon' acc (left :+: right ) x = WhenEmpty
204
- (FindCon' (Eval (Snoc acc 'HereLeft )) left x )
205
- (Pure (FindCon' (Eval (Snoc acc 'HereRight )) right x ))
204
+ (FindCon' (Eval (Snoc acc 'StepLeft )) left x )
205
+ (Pure (FindCon' (Eval (Snoc acc 'StepRight )) right x ))
206
206
FindCon' acc other x = '[]
207
207
208
208
type family WhenEmpty (left :: [a ]) (right :: Exp [a ]) :: [a ] where
209
209
WhenEmpty '[] b = Eval b
210
210
WhenEmpty a _ = a
211
211
212
- type family FindSel (xs :: * -> * ) (x :: Symbol ) :: Where where
213
- FindSel (S1 ('MetaSel ('Just x ) u ss ds ) f ) x = 'Here
214
- FindSel (S1 ('MetaSel ('Just x ) u ss ds ) f :*: rest ) x = 'Here
215
- FindSel ((S1 ('MetaSel ('Just x ) u ss ds ) f :*: other ) :*: rest ) x = 'HereLeft
216
- FindSel ((other :*: S1 ('MetaSel ('Just x ) u ss ds ) f ) :*: rest ) x = 'HereRight
217
- FindSel ((other1 :*: (S1 ('MetaSel ('Just x ) u ss ds ) f :*: other2 )) :*: rest ) x = 'HereRightThenLeft
218
- FindSel ((other1 :*: (other2 :*: S1 ('MetaSel ('Just x ) u ss ds ) f )) :*: rest ) x = 'HereTwoRights
219
- FindSel (other :*: rest ) x = 'There (FindSel rest x )
220
- FindSel nothing x = TypeError ('Text " Could not find selector " ':<>: 'ShowType x )
212
+ type family FindSel (xs :: * -> * ) (x :: Symbol ) :: [WhereStep ] where
213
+ FindSel xs x = WhenEmpty
214
+ (FindSel' '[] xs x )
215
+ (TypeError ('Text " Could not find field " ':<>: 'ShowType x ))
216
+
217
+ type family FindSel' (begin :: [WhereStep ]) (xs :: * -> * ) (x :: Symbol ) :: [WhereStep ] where
218
+ FindSel' acc (S1 ('MetaSel ('Just x ) u ss ds ) f ) x = Eval (Snoc acc 'StepNoMore)
219
+ FindSel' acc (left :*: right ) x = WhenEmpty
220
+ (FindSel' (Eval (Snoc acc 'StepLeft)) left x )
221
+ (Pure (FindSel' (Eval (Snoc acc 'StepRight)) right x ))
222
+ FindSel' acc other x = '[]
221
223
222
224
type family FindEnumChoice (xs :: [ChoiceDef fs ]) (x :: fs ) :: Where where
223
225
FindEnumChoice '[] x = TypeError ('Text " Could not find enum choice " ':<>: 'ShowType x )
@@ -486,13 +488,13 @@ instance (GFromSchemaEnumU1 f (FindCon f (MappingLeft fmap c)), GFromSchemaEnumD
486
488
fromSchemaEnumDecomp _ (Z _) = fromSchemaEnumU1 (Proxy @ f ) (Proxy @ (FindCon f (MappingLeft fmap c )))
487
489
fromSchemaEnumDecomp p (S x) = fromSchemaEnumDecomp p x
488
490
489
- class GFromSchemaEnumU1 (f :: * -> * ) (w :: [Where ]) where
491
+ class GFromSchemaEnumU1 (f :: * -> * ) (w :: [WhereStep ]) where
490
492
fromSchemaEnumU1 :: Proxy f -> Proxy w -> f a
491
- instance GFromSchemaEnumU1 (C1 m U1 ) '[ 'Here ] where
492
- fromSchemaEnumU1 _ _ = ( M1 U1 )
493
- instance GFromSchemaEnumU1 left rest => GFromSchemaEnumU1 (left :+: right ) ('HereLeft ': rest ) where
493
+ instance GFromSchemaEnumU1 (C1 m U1 ) '[ 'StepNoMore ] where
494
+ fromSchemaEnumU1 _ _ = M1 U1
495
+ instance GFromSchemaEnumU1 left rest => GFromSchemaEnumU1 (left :+: right ) ('StepLeft ': rest ) where
494
496
fromSchemaEnumU1 _ _ = L1 (fromSchemaEnumU1 (Proxy @ left ) (Proxy @ rest ))
495
- instance GFromSchemaEnumU1 right rest => GFromSchemaEnumU1 (left :+: right ) ('HereRight ': rest ) where
497
+ instance GFromSchemaEnumU1 right rest => GFromSchemaEnumU1 (left :+: right ) ('StepRight ': rest ) where
496
498
fromSchemaEnumU1 _ _ = R1 (fromSchemaEnumU1 (Proxy @ right ) (Proxy @ rest ))
497
499
498
500
-- ----------
@@ -553,29 +555,18 @@ instance ( GToSchemaRecord sch fmap cs f
553
555
where this = Field (toSchemaRecordSearch (Proxy @ (FindSel f (MappingLeft fmap name ))) x)
554
556
555
557
class GToSchemaRecordSearch (sch :: Schema ts fs )
556
- (t :: FieldType ts ) (f :: * -> * ) (wh :: Where ) where
558
+ (t :: FieldType ts ) (f :: * -> * ) (wh :: [ WhereStep ] ) where
557
559
toSchemaRecordSearch :: Proxy wh -> f a -> FieldValue sch t
558
560
instance GToSchemaFieldType sch t v
559
- => GToSchemaRecordSearch sch t (S1 m (K1 i v )) 'Here where
561
+ => GToSchemaRecordSearch sch t (S1 m (K1 i v )) '[ 'StepNoMore ] where
560
562
toSchemaRecordSearch _ (M1 (K1 x)) = toSchemaFieldType x
561
- instance GToSchemaFieldType sch t v
562
- => GToSchemaRecordSearch sch t (S1 m (K1 i v ) :*: rest ) 'Here where
563
- toSchemaRecordSearch _ (M1 (K1 x) :*: _) = toSchemaFieldType x
564
- instance GToSchemaFieldType sch t v
565
- => GToSchemaRecordSearch sch t ((S1 m (K1 i v ) :*: other ) :*: rest ) 'HereLeft where
566
- toSchemaRecordSearch _ ((M1 (K1 x) :*: _) :*: _) = toSchemaFieldType x
567
- instance GToSchemaFieldType sch t v
568
- => GToSchemaRecordSearch sch t ((other :*: S1 m (K1 i v )) :*: rest ) 'HereRight where
569
- toSchemaRecordSearch _ ((_ :*: M1 (K1 x)) :*: _) = toSchemaFieldType x
570
- instance GToSchemaFieldType sch t v
571
- => GToSchemaRecordSearch sch t ((other1 :*: (S1 m (K1 i v ) :*: other2 )) :*: rest ) 'HereRightThenLeft where
572
- toSchemaRecordSearch _ ((_ :*: (M1 (K1 x) :*: _)) :*: _) = toSchemaFieldType x
573
- instance GToSchemaFieldType sch t v
574
- => GToSchemaRecordSearch sch t ((other1 :*: (other2 :*: S1 m (K1 i v ))) :*: rest ) 'HereTwoRights where
575
- toSchemaRecordSearch _ ((_ :*: (_ :*: M1 (K1 x))) :*: _) = toSchemaFieldType x
576
- instance forall sch t other rest n .
577
- GToSchemaRecordSearch sch t rest n
578
- => GToSchemaRecordSearch sch t (other :*: rest ) ('There n ) where
563
+ instance forall sch t left right n .
564
+ GToSchemaRecordSearch sch t left n
565
+ => GToSchemaRecordSearch sch t (left :*: right ) ('StepLeft ': n ) where
566
+ toSchemaRecordSearch _ (xs :*: _) = toSchemaRecordSearch (Proxy @ n ) xs
567
+ instance forall sch t left right n .
568
+ GToSchemaRecordSearch sch t right n
569
+ => GToSchemaRecordSearch sch t (left :*: right ) ('StepRight ': n ) where
579
570
toSchemaRecordSearch _ (_ :*: xs) = toSchemaRecordSearch (Proxy @ n ) xs
580
571
581
572
-- 'fromSchema' for records
0 commit comments