on master help sign in
Inline prisms better
commit5d8b507c71a2927438cc260226a3962eb9c73d97 authorCsongor Kiss <kiss.csongor.kiss@gmail.com> dateFri 19 Jan 2018, 14:24 (9 years ago) parent9d943c2
7 files changed+12−7
src/Data/Generics/Internal/Profunctor/Iso.hs+1 src/Data/Generics/Internal/Profunctor/Prism.hs+1−3 src/Data/Generics/Internal/VL/Prism.hs+1−1 src/Data/Generics/Sum/Constructors.hs+2−1 src/Data/Generics/Sum/Internal/Subtype.hs+3 src/Data/Generics/Sum/Subtype.hs+2−1 src/Data/Generics/Sum/Typed.hs+2−1
src/Data/Generics/Internal/Profunctor/Iso.hs+1
@@ -50,6 +50,7 @@ sumIso = iso back forth
5050 forth (Right r) = R1 r
5151 back (L1 l) = Left l
5252 back (R1 r) = Right r
53+{-# INLINE sumIso #-}
5354
5455prodIso :: Iso ((a :*: b) x) ((a' :*: b') x) (a x, b x) (a' x, b' x)
5556prodIso = 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)
4848_Right :: Prism (Either c a) (Either c b) a b
4949_Right = prism Right $ either (Left . Left) Right
5050
51−prismPRavel ::
52− (Market a b a b -> Market a b s t)
53− -> Prism s t a b
51+prismPRavel :: (Market a b a b -> Market a b s t) -> Prism s t a b
5452prismPRavel l pab = (prism2prismp $ l idPrism) pab
5553
5654--------------------------------------------------------------------------------
src/Data/Generics/Internal/VL/Prism.hs+1−1
@@ -23,7 +23,7 @@ module Data.Generics.Internal.VL.Prism where
2323import Data.Functor.Identity (Identity(..))
2424import Data.Profunctor (Choice(..), Profunctor(..))
2525import Data.Coerce
26−import Data.Generics.Internal.Profunctor.Prism (Market (..), plus, idPrism)
26+import Data.Generics.Internal.Profunctor.Prism (Market (..), plus, idPrism, prismPRavel)
2727import Data.Tagged
2828import Data.Profunctor.Unsafe ((#.), (.#))
2929
src/Data/Generics/Sum/Constructors.hs+2−1
@@ -41,6 +41,7 @@ import GHC.Generics (Generic (Rep))
4141import GHC.TypeLits (Symbol, TypeError, ErrorMessage (..))
4242import Data.Generics.Internal.VL.Prism
4343import Data.Generics.Internal.Profunctor.Iso
44+import Data.Generics.Internal.Profunctor.Prism (prismPRavel)
4445
4546-- $setup
4647-- == /Running example:/
@@ -122,7 +123,7 @@ instance
122123 , s ~ Infer t b' a
123124 ) => AsConstructor ctor s t a b where
124125
125− _Ctor eta = prismRavel (repIso . _GCtor @ctor) eta
126+ _Ctor eta = prismRavel (prismPRavel (repIso . _GCtor @ctor)) eta
126127 {-# INLINE _Ctor #-}
127128
128129-- See Note [Uncluttering type signatures]
src/Data/Generics/Sum/Internal/Subtype.hs+3
@@ -45,15 +45,18 @@ instance
4545 , GAsSubtype r supf
4646 ) => GAsSubtype (l :+: r) supf where
4747 _GSub = without' _GSub _GSub . fromIso sumIso
48+ {-# INLINE _GSub #-}
4849
4950instance
5051 ( GIsList () subf subf as as
5152 , GAsType supf as
5253 ) => GAsSubtype (C1 meta subf) supf where
5354 _GSub = _GTyped . fromIso (glist @()) . fromIso mIso
55+ {-# INLINE _GSub #-}
5456
5557-- instance GAsType supf a => GAsSubtype (S1 meta (Rec0 a)) supf where
5658-- _GSub = _GTyped . fromIso (mIso . kIso)
5759
5860instance GAsSubtype subf supf => GAsSubtype (D1 meta subf) supf where
5961 _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
3333import GHC.Generics (Generic (Rep))
3434import Data.Generics.Internal.VL.Prism
3535import Data.Generics.Internal.Profunctor.Iso
36+import Data.Generics.Internal.Profunctor.Prism (prismPRavel)
3637
3738-- $setup
3839-- == /Running example:/
@@ -107,7 +108,7 @@ instance
107108 , GAsSubtype (Rep sub) (Rep sup)
108109 ) => AsSubtype sub sup where
109110
110− _Sub = prismRavel (repIso . _GSub . fromIso repIso)
111+ _Sub f = prismRavel (prismPRavel (repIso . _GSub . fromIso repIso)) f
111112
112113-- See Note [Uncluttering type signatures]
113114instance {-# OVERLAPPING #-} AsSubtype a Void where
src/Data/Generics/Sum/Typed.hs+2−1
@@ -40,6 +40,7 @@ import Data.Generics.Internal.Void
4040import Data.Generics.Product.Internal.List
4141import Data.Generics.Internal.VL.Prism
4242import Data.Generics.Internal.Profunctor.Iso
43+import Data.Generics.Internal.Profunctor.Prism (prismPRavel)
4344
4445-- $setup
4546-- >>> :set -XTypeApplications
@@ -106,7 +107,7 @@ instance
106107 , GAsType (Rep s) as
107108 ) => AsType a s where
108109
109− _Typed = prismRavel (repIso . _GTyped @_ @as . tupled)
110+ _Typed eta = prismRavel (prismPRavel (repIso . _GTyped @_ @as . tupled)) eta
110111 {-# INLINE _Typed #-}
111112
112113-- See Note [Uncluttering type signatures]