@@ -30,7 +30,8 @@ module Data.Generics.Product.Types
30 ( -- *Traversals
30 ( -- *Traversals
32 -- $example
32 -- $example
33− HasTypes (..)
33+ HasTypes
36import Data.Kind
37import Data.Kind
@@ -40,80 +41,84 @@ import Data.Generics.Internal.VL.Traversal
41-- TODO [1.0.0.0]: use type-changing variant internally
42-- TODO [1.0.0.0]: use type-changing variant internally
43−class HasTypes a s where
44− types :: Traversal' s a
44+types :: forall a s. HasTypes s a => Traversal' s a
48+class HasTypes s a where
49+ types_ :: Traversal' s a
46− default types :: Traversal' s a
51+ default types_ :: Traversal' s a
47− types _ = pure
52+ types_ _ = pure
48− {-# INLINE types #-}
53+ {-# INLINE types_ #-}
51− ( Hastypes' (Interesting s a) a s
56+ ( HasTypes' (Interesting s a) s a
52− ) => HasTypes a s where
57+ ) => HasTypes s a where
53− types = types' @(Interesting s a)
58+ types_ = types' @(Interesting s a)
54− {-# INLINE types #-}
59+ {-# INLINE types_ #-}
56−class Hastypes' (t :: Bool) a s where
61+class HasTypes' (t :: Bool) s a where
57 types' :: Traversal' s a
62 types' :: Traversal' s a
60− ( GHasTypes a (Rep s)
65+ ( GHasTypes (Rep s) a
61 , Generic s
66 , Generic s
62− ) => Hastypes' 'True a s where
67+ ) => HasTypes' 'True s a where
63− types' f s = to <$> gtypes f (from s)
68+ types' f s = to <$> gtypes_ f (from s)
64 --{-# INLINE types' #-}
69 --{-# INLINE types' #-}
66−instance Hastypes' 'False a s where
71+instance HasTypes' 'False s a where
67 types' _ = pure
72 types' _ = pure
68 --{-# INLINE types' #-}
73 --{-# INLINE types' #-}
70−instance {-# OVERLAPPING #-} HasTypes a Bool
75+instance {-# OVERLAPPING #-} HasTypes Bool a
71−instance {-# OVERLAPPING #-} HasTypes a Char
76+instance {-# OVERLAPPING #-} HasTypes Char a
72−instance {-# OVERLAPPING #-} HasTypes a Double
77+instance {-# OVERLAPPING #-} HasTypes Double a
73−instance {-# OVERLAPPING #-} HasTypes a Float
78+instance {-# OVERLAPPING #-} HasTypes Float a
74−instance {-# OVERLAPPING #-} HasTypes a Int
79+instance {-# OVERLAPPING #-} HasTypes Int a
75−instance {-# OVERLAPPING #-} HasTypes a Integer
80+instance {-# OVERLAPPING #-} HasTypes Integer a
76−instance {-# OVERLAPPING #-} HasTypes a Ordering
81+instance {-# OVERLAPPING #-} HasTypes Ordering a
78--------------------------------------------------------------------------------
83--------------------------------------------------------------------------------
80−class GHasTypes a s where
85+class GHasTypes s a where
81− gtypes :: Traversal' (s x) a
86+ gtypes_ :: Traversal' (s x) a
84− ( GHasTypes a l
89+ ( GHasTypes l a
85− , GHasTypes a r
90+ , GHasTypes r a
86− ) => GHasTypes a (l :*: r) where
91+ ) => GHasTypes (l :*: r) a where
87− gtypes f (l :*: r) = (:*:) <$> gtypes f l <*> gtypes f r
92+ gtypes_ f (l :*: r) = (:*:) <$> gtypes_ f l <*> gtypes_ f r
88− {-# INLINE gtypes #-}
93+ {-# INLINE gtypes_ #-}
91− ( GHasTypes a l
96+ ( GHasTypes l a
92− , GHasTypes a r
97+ , GHasTypes r a
93− ) => GHasTypes a (l :+: r) where
98+ ) => GHasTypes (l :+: r) a where
94− gtypes f (L1 l) = L1 <$> gtypes f l
99+ gtypes_ f (L1 l) = L1 <$> gtypes_ f l
95− gtypes f (R1 r) = R1 <$> gtypes f r
100+ gtypes_ f (R1 r) = R1 <$> gtypes_ f r
96− {-# INLINE gtypes #-}
101+ {-# INLINE gtypes_ #-}
98−instance (GHasTypes a s) => GHasTypes a (M1 m meta s) where
103+instance (GHasTypes s a) => GHasTypes (M1 m meta s) a where
99− gtypes f (M1 s) = M1 <$> gtypes f s
104+ gtypes_ f (M1 s) = M1 <$> gtypes_ f s
100− {-# INLINE gtypes #-}
105+ {-# INLINE gtypes_ #-}
102−instance {-# OVERLAPPING #-} GHasTypes a (Rec0 a) where
107+instance {-# OVERLAPPING #-} GHasTypes (Rec0 a) a where
103− gtypes f (K1 x) = K1 <$> f x
108+ gtypes_ f (K1 x) = K1 <$> f x
104− {-# INLINE gtypes #-}
109+ {-# INLINE gtypes_ #-}
106−instance HasTypes a b => GHasTypes a (Rec0 b) where
111+instance HasTypes b a => GHasTypes (Rec0 b) a where
107− gtypes f (K1 x) = K1 <$> types @a f x
112+ gtypes_ f (K1 x) = K1 <$> types_ @_ @a f x
108− {-# INLINE gtypes #-}
113+ {-# INLINE gtypes_ #-}
110−instance GHasTypes a U1 where
115+instance GHasTypes U1 a where
111− gtypes _ _ = pure U1
116+ gtypes_ _ _ = pure U1
112− {-# INLINE gtypes #-}
117+ {-# INLINE gtypes_ #-}
114−instance GHasTypes a V1 where
119+instance GHasTypes V1 a where
115− gtypes _ = pure
120+ gtypes_ _ = pure
116− {-# INLINE gtypes #-}
121+ {-# INLINE gtypes_ #-}
118type Interesting f a = Snd (Interesting' (Rep f) a '[f])
123type Interesting f a = Snd (Interesting' (Rep f) a '[f])