on master help sign in
Pass all doctests
commit3a492a6af1cc110b2995c5da170d75376a6e2b6e authorCsongor Kiss <kiss.csongor.kiss@gmail.com> dateTue 23 Jan 2018, 20:14 (9 years ago) parent2c14f01
4 files changed+6−11
src/Data/Generics/Internal/Profunctor/Lens.hs−7 src/Data/Generics/Internal/VL/Prism.hs+4−1 src/Data/Generics/Product/Subtype.hs+1−1 src/Data/Generics/Sum/Subtype.hs+1−2
src/Data/Generics/Internal/Profunctor/Lens.hs−7
@@ -23,7 +23,6 @@ module Data.Generics.Internal.Profunctor.Lens where
2323
2424import Data.Profunctor (Profunctor(..), Strong(..))
2525import Data.Bifunctor
26−import Data.Profunctor.Unsafe ((#.))
2726import Data.Tagged
2827import GHC.Generics
2928import Data.Generics.Internal.Profunctor.Iso
@@ -63,12 +62,6 @@ idLens :: ALens a b a b
6362idLens = ALens (fork (const ()) id) snd
6463{-# INLINE idLens #-}
6564
66−
67−
68−build :: (Tagged b b -> Tagged t t) -> b -> t
69−build p = unTagged . p . Tagged
70−
71−
7265-- | Lens focusing on the first element of a product
7366first :: Lens ((a :*: b) x) ((a' :*: b) x) (a x) (a' x)
7467first
src/Data/Generics/Internal/VL/Prism.hs+4−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, prismPRavel)
26+import Data.Generics.Internal.Profunctor.Prism (Market (..), plus, idPrism)
2727import Data.Tagged
2828import Data.Profunctor.Unsafe ((#.), (.#))
2929import Data.Monoid (First (..))
@@ -45,6 +45,9 @@ s ^? l = getFirst (fmof l (First #. Just) s)
4545match :: Prism s t a b -> s -> Either t a
4646match k = withPrism k $ \_ _match -> _match
4747
48+(#) :: (Tagged b (Identity b) -> Tagged t (Identity t)) -> b -> t
49+(#) = build
50+
4851prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
4952prism bt seta eta = dimap (\x -> plus pure id (seta x)) (either id (\x -> fmap bt x)) (right' eta)
5053{-# INLINE prism #-}
src/Data/Generics/Product/Subtype.hs+1−1
@@ -40,7 +40,7 @@ import Data.Generics.Product.Internal.Subtype
4040import GHC.Generics (Generic (Rep, to, from) )
4141import GHC.TypeLits (Symbol, TypeError, ErrorMessage (..))
4242import Data.Kind (Type, Constraint)
43−import Data.Generics.Internal.Profunctor.Lens
43+import Data.Generics.Internal.Profunctor.Lens hiding (set)
4444
4545-- $setup
4646-- == /Running example:/
src/Data/Generics/Sum/Subtype.hs+1−2
@@ -33,7 +33,6 @@ 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)
3736
3837-- $setup
3938-- == /Running example:/
@@ -42,7 +41,7 @@ import Data.Generics.Internal.Profunctor.Prism (prismPRavel)
4241-- >>> :set -XDataKinds
4342-- >>> :set -XDeriveGeneric
4443-- >>> import GHC.Generics
45−-- >>> :m +Data.Generics.Internal.Lens
44+-- >>> :m +Data.Generics.Internal.VL.Prism
4645-- >>> :{
4746-- data Animal
4847-- = Dog Dog