@@ -31,99 +31,86 @@ module Data.Generics.Product.Types
32 -- $example
32 -- $example
33 HasTypes (..)
33 HasTypes (..)
37−import Data.Generics.Product.Internal.Types
38import Data.Kind
36import Data.Kind
39import Data.Type.Bool
37import Data.Type.Bool
41import GHC.Generics
39import GHC.Generics
42import Data.Generics.Internal.VL.Traversal
40import Data.Generics.Internal.VL.Traversal
43−import Data.Generics.Internal.VL.Iso
45class HasTypes a s where
42class HasTypes a s where
46 types :: Traversal' s a
43 types :: Traversal' s a
48−instance
45+ default types :: Traversal' s a
49− ( Generic s
46+ types _ = pure
50− , GHasTypes (Rep s) '[a]
51− ) => HasTypes a s where
52− types = confusing (\f -> (repIso . gtypes) (f :> HNil))
53 {-# INLINE types #-}
47 {-# INLINE types #-}
55−class HasTypesDeep a s where
56− typesDeep :: Traversal' s a
58− default typesDeep :: Traversal' s a
60− {-# INLINE typesDeep #-}
63− ( HasTypesDeep1 (Interesting s a) a s
50+ ( HasTypes1 (Interesting s a) a s
64− ) => HasTypesDeep a s where
51+ ) => HasTypes a s where
65− typesDeep = typesDeep1 @(Interesting s a)
52+ types = types1 @(Interesting s a)
66− {-# INLINE typesDeep #-}
53+ {-# INLINE types #-}
68−class HasTypesDeep1 (t :: Bool) a s where
55+class HasTypes1 (t :: Bool) a s where
69− typesDeep1 :: Traversal' s a
56+ types1 :: Traversal' s a
72− ( GHasTypesDeep a (Rep s)
59+ ( GHasTypes a (Rep s)
73 , Generic s
60 , Generic s
74− ) => HasTypesDeep1 'True a s where
61+ ) => HasTypes1 'True a s where
75− typesDeep1 f s = to <$> gtypesDeep f (from s)
62+ types1 f s = to <$> gtypes f (from s)
76− --{-# INLINE typesDeep1 #-}
63+ --{-# INLINE types1 #-}
78−instance HasTypesDeep1 'False a s where
65+instance HasTypes1 'False a s where
79− typesDeep1 _ = pure
66+ types1 _ = pure
80− --{-# INLINE typesDeep1 #-}
67+ --{-# INLINE types1 #-}
82−instance {-# OVERLAPPING #-} HasTypesDeep a Bool
69+instance {-# OVERLAPPING #-} HasTypes a Bool
83−instance {-# OVERLAPPING #-} HasTypesDeep a Char
70+instance {-# OVERLAPPING #-} HasTypes a Char
84−instance {-# OVERLAPPING #-} HasTypesDeep a Double
71+instance {-# OVERLAPPING #-} HasTypes a Double
85−instance {-# OVERLAPPING #-} HasTypesDeep a Float
72+instance {-# OVERLAPPING #-} HasTypes a Float
86−instance {-# OVERLAPPING #-} HasTypesDeep a Int
73+instance {-# OVERLAPPING #-} HasTypes a Int
87−instance {-# OVERLAPPING #-} HasTypesDeep a Integer
74+instance {-# OVERLAPPING #-} HasTypes a Integer
88−instance {-# OVERLAPPING #-} HasTypesDeep a Ordering
75+instance {-# OVERLAPPING #-} HasTypes a Ordering
90--------------------------------------------------------------------------------
77--------------------------------------------------------------------------------
92−class GHasTypesDeep a s where
79+class GHasTypes a s where
93− gtypesDeep :: Traversal' (s x) a
80+ gtypes :: Traversal' (s x) a
96− ( GHasTypesDeep a l
83+ ( GHasTypes a l
97− , GHasTypesDeep a r
84+ , GHasTypes a r
98− ) => GHasTypesDeep a (l :*: r) where
85+ ) => GHasTypes a (l :*: r) where
99− gtypesDeep f (l :*: r) = (:*:) <$> gtypesDeep f l <*> gtypesDeep f r
86+ gtypes f (l :*: r) = (:*:) <$> gtypes f l <*> gtypes f r
100− {-# INLINE gtypesDeep #-}
87+ {-# INLINE gtypes #-}
103− ( GHasTypesDeep a l
90+ ( GHasTypes a l
104− , GHasTypesDeep a r
91+ , GHasTypes a r
105− ) => GHasTypesDeep a (l :+: r) where
92+ ) => GHasTypes a (l :+: r) where
106− gtypesDeep f (L1 l) = L1 <$> gtypesDeep f l
93+ gtypes f (L1 l) = L1 <$> gtypes f l
107− gtypesDeep f (R1 r) = R1 <$> gtypesDeep f r
94+ gtypes f (R1 r) = R1 <$> gtypes f r
108− {-# INLINE gtypesDeep #-}
95+ {-# INLINE gtypes #-}
110−instance (GHasTypesDeep a s) => GHasTypesDeep a (M1 m meta s) where
97+instance (GHasTypes a s) => GHasTypes a (M1 m meta s) where
111− gtypesDeep f (M1 s) = M1 <$> gtypesDeep f s
98+ gtypes f (M1 s) = M1 <$> gtypes f s
112− {-# INLINE gtypesDeep #-}
99+ {-# INLINE gtypes #-}
114−instance {-# OVERLAPPING #-} GHasTypesDeep a (Rec0 a) where
101+instance {-# OVERLAPPING #-} GHasTypes a (Rec0 a) where
115− gtypesDeep f (K1 x) = K1 <$> f x
102+ gtypes f (K1 x) = K1 <$> f x
116− {-# INLINE gtypesDeep #-}
103+ {-# INLINE gtypes #-}
118−instance HasTypesDeep a b => GHasTypesDeep a (Rec0 b) where
105+instance HasTypes a b => GHasTypes a (Rec0 b) where
119− gtypesDeep f (K1 x) = K1 <$> typesDeep @a f x
106+ gtypes f (K1 x) = K1 <$> types @a f x
120− {-# INLINE gtypesDeep #-}
107+ {-# INLINE gtypes #-}
122−instance GHasTypesDeep a U1 where
109+instance GHasTypes a U1 where
123− gtypesDeep _ _ = pure U1
110+ gtypes _ _ = pure U1
124− {-# INLINE gtypesDeep #-}
111+ {-# INLINE gtypes #-}
126−--instance GHasTypesDeep a V1 where
113+--instance GHasTypes a V1 where
128type Interesting f a = Interesting' f (Rep f) a
115type Interesting f a = Interesting' f (Rep f) a