on master help sign in
Inline prisms better
5d8b507Csongor Kiss
src/Data/Generics/Internal/Profunctor/Iso.hs+1
@@ -50,6 +50,7 @@ sumIso = iso back forth
50 forth (Right r) = R1 r
50 forth (Right r) = R1 r
51 back (L1 l) = Left l
51 back (L1 l) = Left l
52 back (R1 r) = Right r
52 back (R1 r) = Right r
53+{-# INLINE sumIso #-}
53
54
54prodIso :: Iso ((a :*: b) x) ((a' :*: b') x) (a x, b x) (a' x, b' x)
55prodIso :: Iso ((a :*: b) x) ((a' :*: b') x) (a x, b x) (a' x, b' x)
55prodIso = iso (\(a :*: b) -> (a, b)) (\(a, b) -> (a :*: b))
56prodIso = iso (\(a :*: b) -> (a, b)) (\(a, b) -> (a :*: b))
src/Data/Generics/Internal/Profunctor/Prism.hs+1−3
@@ -48,9 +48,7 @@ _Left = prism Left $ either Right (Left . Right)
48_Right :: Prism (Either c a) (Either c b) a b
48_Right :: Prism (Either c a) (Either c b) a b
49_Right = prism Right $ either (Left . Left) Right
49_Right = prism Right $ either (Left . Left) Right
50
50
51−prismPRavel ::
52− (Market a b a b -> Market a b s t)
51+prismPRavel :: (Market a b a b -> Market a b s t) -> Prism s t a b
53− -> Prism s t a b
54prismPRavel l pab = (prism2prismp $ l idPrism) pab
52prismPRavel l pab = (prism2prismp $ l idPrism) pab
55
53
56--------------------------------------------------------------------------------
54--------------------------------------------------------------------------------
src/Data/Generics/Internal/VL/Prism.hs+1−1
@@ -23,7 +23,7 @@ module Data.Generics.Internal.VL.Prism where
23import Data.Functor.Identity (Identity(..))
23import Data.Functor.Identity (Identity(..))
24import Data.Profunctor (Choice(..), Profunctor(..))
24import Data.Profunctor (Choice(..), Profunctor(..))
25import Data.Coerce
25import Data.Coerce
26−import Data.Generics.Internal.Profunctor.Prism (Market (..), plus, idPrism)
26+import Data.Generics.Internal.Profunctor.Prism (Market (..), plus, idPrism, prismPRavel)
27import Data.Tagged
27import Data.Tagged
28import Data.Profunctor.Unsafe ((#.), (.#))
28import Data.Profunctor.Unsafe ((#.), (.#))
29
29
src/Data/Generics/Sum/Constructors.hs+2−1
@@ -41,6 +41,7 @@ import GHC.Generics (Generic (Rep))
41import GHC.TypeLits (Symbol, TypeError, ErrorMessage (..))
41import GHC.TypeLits (Symbol, TypeError, ErrorMessage (..))
42import Data.Generics.Internal.VL.Prism
42import Data.Generics.Internal.VL.Prism
43import Data.Generics.Internal.Profunctor.Iso
43import Data.Generics.Internal.Profunctor.Iso
44+import Data.Generics.Internal.Profunctor.Prism (prismPRavel)
44
45
45-- $setup
46-- $setup
46-- == /Running example:/
47-- == /Running example:/
@@ -122,7 +123,7 @@ instance
122 , s ~ Infer t b' a
123 , s ~ Infer t b' a
123 ) => AsConstructor ctor s t a b where
124 ) => AsConstructor ctor s t a b where
124
125
125− _Ctor eta = prismRavel (repIso . _GCtor @ctor) eta
126+ _Ctor eta = prismRavel (prismPRavel (repIso . _GCtor @ctor)) eta
126 {-# INLINE _Ctor #-}
127 {-# INLINE _Ctor #-}
127
128
128-- See Note [Uncluttering type signatures]
129-- See Note [Uncluttering type signatures]
src/Data/Generics/Sum/Internal/Subtype.hs+3
@@ -45,15 +45,18 @@ instance
45 , GAsSubtype r supf
45 , GAsSubtype r supf
46 ) => GAsSubtype (l :+: r) supf where
46 ) => GAsSubtype (l :+: r) supf where
47 _GSub = without' _GSub _GSub . fromIso sumIso
47 _GSub = without' _GSub _GSub . fromIso sumIso
48+ {-# INLINE _GSub #-}
48
49
49instance
50instance
50 ( GIsList () subf subf as as
51 ( GIsList () subf subf as as
51 , GAsType supf as
52 , GAsType supf as
52 ) => GAsSubtype (C1 meta subf) supf where
53 ) => GAsSubtype (C1 meta subf) supf where
53 _GSub = _GTyped . fromIso (glist @()) . fromIso mIso
54 _GSub = _GTyped . fromIso (glist @()) . fromIso mIso
55+ {-# INLINE _GSub #-}
54
56
55-- instance GAsType supf a => GAsSubtype (S1 meta (Rec0 a)) supf where
57-- instance GAsType supf a => GAsSubtype (S1 meta (Rec0 a)) supf where
56-- _GSub = _GTyped . fromIso (mIso . kIso)
58-- _GSub = _GTyped . fromIso (mIso . kIso)
57
59
58instance GAsSubtype subf supf => GAsSubtype (D1 meta subf) supf where
60instance GAsSubtype subf supf => GAsSubtype (D1 meta subf) supf where
59 _GSub = _GSub . fromIso mIso
61 _GSub = _GSub . fromIso mIso
62+ {-# INLINE _GSub #-}
src/Data/Generics/Sum/Subtype.hs+2−1
@@ -33,6 +33,7 @@ import Data.Generics.Sum.Internal.Subtype
33import GHC.Generics (Generic (Rep))
33import GHC.Generics (Generic (Rep))
34import Data.Generics.Internal.VL.Prism
34import Data.Generics.Internal.VL.Prism
35import Data.Generics.Internal.Profunctor.Iso
35import Data.Generics.Internal.Profunctor.Iso
36+import Data.Generics.Internal.Profunctor.Prism (prismPRavel)
36
37
37-- $setup
38-- $setup
38-- == /Running example:/
39-- == /Running example:/
@@ -107,7 +108,7 @@ instance
107 , GAsSubtype (Rep sub) (Rep sup)
108 , GAsSubtype (Rep sub) (Rep sup)
108 ) => AsSubtype sub sup where
109 ) => AsSubtype sub sup where
109
110
110− _Sub = prismRavel (repIso . _GSub . fromIso repIso)
111+ _Sub f = prismRavel (prismPRavel (repIso . _GSub . fromIso repIso)) f
111
112
112-- See Note [Uncluttering type signatures]
113-- See Note [Uncluttering type signatures]
113instance {-# OVERLAPPING #-} AsSubtype a Void where
114instance {-# OVERLAPPING #-} AsSubtype a Void where
src/Data/Generics/Sum/Typed.hs+2−1
@@ -40,6 +40,7 @@ import Data.Generics.Internal.Void
40import Data.Generics.Product.Internal.List
40import Data.Generics.Product.Internal.List
41import Data.Generics.Internal.VL.Prism
41import Data.Generics.Internal.VL.Prism
42import Data.Generics.Internal.Profunctor.Iso
42import Data.Generics.Internal.Profunctor.Iso
43+import Data.Generics.Internal.Profunctor.Prism (prismPRavel)
43
44
44-- $setup
45-- $setup
45-- >>> :set -XTypeApplications
46-- >>> :set -XTypeApplications
@@ -106,7 +107,7 @@ instance
106 , GAsType (Rep s) as
107 , GAsType (Rep s) as
107 ) => AsType a s where
108 ) => AsType a s where
108
109
109− _Typed = prismRavel (repIso . _GTyped @_ @as . tupled)
110+ _Typed eta = prismRavel (prismPRavel (repIso . _GTyped @_ @as . tupled)) eta
110 {-# INLINE _Typed #-}
111 {-# INLINE _Typed #-}
111
112
112-- See Note [Uncluttering type signatures]
113-- See Note [Uncluttering type signatures]