on master help sign in
Make some more doctests work
commit2c14f01e9a02890828c4391356bedc95be00810b authorMatthew Pickering <matthewtpickering@gmail.com> dateTue 23 Jan 2018, 17:07 (9 years ago) parentae60726
11 files changed+28−24
src/Data/Generics/Internal/Profunctor/Lens.hs−13 src/Data/Generics/Internal/VL/Lens.hs+12−3 src/Data/Generics/Internal/VL/Prism.hs+8 src/Data/Generics/Product/Any.hs+1−1 src/Data/Generics/Product/Fields.hs+1−1 src/Data/Generics/Product/Positions.hs+1−1 src/Data/Generics/Product/Subtype.hs+1−1 src/Data/Generics/Product/Typed.hs+1−1 src/Data/Generics/Sum/Any.hs+1−1 src/Data/Generics/Sum/Constructors.hs+1−1 src/Data/Generics/Sum/Typed.hs+1−1
src/Data/Generics/Internal/Profunctor/Lens.hs−13
@@ -21,8 +21,6 @@
2121-----------------------------------------------------------------------------
2222module Data.Generics.Internal.Profunctor.Lens where
2323
24−import Control.Applicative (Const(..))
25−import Data.Monoid (First (..))
2624import Data.Profunctor (Profunctor(..), Strong(..))
2725import Data.Bifunctor
2826import Data.Profunctor.Unsafe ((#.))
@@ -36,10 +34,6 @@ type Lens s t a b
3634type LensLike p s t a b
3735 = p a b -> p s t
3836
39−-- | Getting
40−(^.) :: s -> ((a -> Const a a) -> s -> Const a s) -> a
41−s ^. l = getConst (l Const s)
42−infixl 8 ^.
4337
4438ravel :: (ALens a b a b -> ALens a b s t) -> Lens s t a b
4539ravel l pab = conv (l idLens) pab
@@ -69,14 +63,7 @@ idLens :: ALens a b a b
6963idLens = ALens (fork (const ()) id) snd
7064{-# INLINE idLens #-}
7165
72−infixr 4 .~
73−(.~) :: ((a -> b) -> s -> t) -> b -> s -> t
74−(.~) f b s = set f (s, b)
7566
76−infixl 8 ^?
77−(^?) :: s -> ((a -> Const (First a) a) -> s -> Const (First a) s) -> Maybe a
78−s ^? l = getFirst (fmof l (First #. Just) s)
79− where fmof l' f = getConst #. l' (Const #. f)
8067
8168build :: (Tagged b b -> Tagged t t) -> b -> t
8269build p = unTagged . p . Tagged
src/Data/Generics/Internal/VL/Lens.hs+12−3
@@ -23,8 +23,7 @@ module Data.Generics.Internal.VL.Lens where
2323
2424import Control.Applicative (Const(..))
2525import Data.Functor.Identity (Identity(..))
26−import Data.Generics.Internal.Profunctor.Lens (ALens (..), (^.), idLens)
27−import GHC.Exts (inline, oneShot)
26+import Data.Generics.Internal.Profunctor.Lens (ALens (..), idLens)
2827
2928-- | Type alias for lens
3029type Lens' s a
@@ -36,8 +35,17 @@ type Lens s t a b
3635view :: ((a -> Const a a) -> s -> Const a s) -> s -> a
3736view l s = (^.) s l
3837
38+-- | Getting
39+(^.) :: s -> ((a -> Const a a) -> s -> Const a s) -> a
40+s ^. l = getConst (l Const s)
41+infixl 8 ^.
42+
43+infixr 4 .~
44+(.~) :: ((a -> Identity b) -> s -> Identity t) -> b -> s -> t
45+(.~) f b = runIdentity . f (Identity . const b)
46+
3947set :: Lens s t a b -> b -> s -> t
40−set l x = runIdentity . l (Identity . const x)
48+set l x = l .~ x
4149
4250lens2lensvl :: ALens a b s t -> Lens s t a b
4351lens2lensvl (ALens _get _set) =
@@ -50,6 +58,7 @@ ravel :: (ALens a b a b -> ALens a b s t)
5058 -> Lens s t a b
5159ravel l pab = (lens2lensvl $ l idLens) pab
5260
61+
5362lens :: (s -> a) -> ((s, b) -> t) -> Lens s t a b
5463lens get _set = \f x -> curry _set x <$> f (get x)
5564{-# INLINE[0] lens #-}
src/Data/Generics/Internal/VL/Prism.hs+8
@@ -26,6 +26,8 @@ import Data.Coerce
2626import Data.Generics.Internal.Profunctor.Prism (Market (..), plus, idPrism, prismPRavel)
2727import Data.Tagged
2828import Data.Profunctor.Unsafe ((#.), (.#))
29+import Data.Monoid (First (..))
30+import Control.Applicative (Const(..))
2931
3032-- | Type alias for prism
3133type Prism s t a b
@@ -34,6 +36,12 @@ type Prism s t a b
3436type Prism' s a
3537 = Prism s s a a
3638
39+infixl 8 ^?
40+(^?) :: s -> ((a -> Const (First a) a) -> s -> Const (First a) s) -> Maybe a
41+s ^? l = getFirst (fmof l (First #. Just) s)
42+ where fmof l' f = getConst #. l' (Const #. f)
43+
44+
3745match :: Prism s t a b -> s -> Either t a
3846match k = withPrism k $ \_ _match -> _match
3947
src/Data/Generics/Product/Any.hs+1−1
@@ -41,7 +41,7 @@ import Data.Generics.Product.Typed
4141-- >>> :set -XDataKinds
4242-- >>> :set -XDeriveGeneric
4343-- >>> import GHC.Generics
44−-- >>> :m +Data.Generics.Internal.Lens
44+-- >>> :m +Data.Generics.Internal.VL.Lens
4545-- >>> :{
4646-- data Human = Human
4747-- { name :: String
src/Data/Generics/Product/Fields.hs+1−1
@@ -56,7 +56,7 @@ import Data.Generics.Internal.Profunctor.Lens as P
5656-- >>> :set -XGADTs
5757-- >>> :set -XFlexibleContexts
5858-- >>> import GHC.Generics
59−-- >>> :m +Data.Generics.Internal.Lens
59+-- >>> :m +Data.Generics.Internal.VL.Lens
6060-- >>> :m +Data.Function
6161-- >>> :{
6262-- data Human a
src/Data/Generics/Product/Positions.hs+1−1
@@ -58,7 +58,7 @@ import Data.Generics.Internal.Profunctor.Lens
5858-- >>> :set -XGADTs
5959-- >>> :set -XFlexibleContexts
6060-- >>> import GHC.Generics
61−-- >>> :m +Data.Generics.Internal.Lens
61+-- >>> :m +Data.Generics.Internal.VL.Lens
6262-- >>> :m +Data.Function
6363-- >>> :{
6464-- data Human = Human
src/Data/Generics/Product/Subtype.hs+1−1
@@ -50,7 +50,7 @@ import Data.Generics.Internal.Profunctor.Lens
5050-- >>> :set -XDeriveGeneric
5151-- >>> :set -XDuplicateRecordFields
5252-- >>> import GHC.Generics
53−-- >>> :m +Data.Generics.Internal.Lens
53+-- >>> :m +Data.Generics.Internal.VL.Lens
5454-- >>> :{
5555-- data Human = Human
5656-- { name :: String
src/Data/Generics/Product/Typed.hs+1−1
@@ -47,7 +47,7 @@ import Data.Generics.Internal.Profunctor.Lens
4747-- >>> :set -XDataKinds
4848-- >>> :set -XDeriveGeneric
4949-- >>> import GHC.Generics
50−-- >>> :m +Data.Generics.Internal.Lens
50+-- >>> :m +Data.Generics.Internal.VL.Lens
5151-- >>> :{
5252-- data Human
5353-- = Human
src/Data/Generics/Sum/Any.hs+1−1
@@ -39,7 +39,7 @@ import Data.Generics.Internal.VL.Prism
3939-- >>> :set -XDataKinds
4040-- >>> :set -XDeriveGeneric
4141-- >>> import GHC.Generics
42−-- >>> :m +Data.Generics.Internal.Lens
42+-- >>> :m +Data.Generics.Internal.VL.Prism
4343-- >>> :{
4444-- data Animal
4545-- = Dog Dog
src/Data/Generics/Sum/Constructors.hs+1−1
@@ -52,7 +52,7 @@ import Data.Generics.Internal.Profunctor.Prism (prismPRavel)
5252-- >>> :set -XFlexibleContexts
5353-- >>> :set -XTypeFamilies
5454-- >>> import GHC.Generics
55−-- >>> :m +Data.Generics.Internal.Lens
55+-- >>> :m +Data.Generics.Internal.VL.Prism
5656-- >>> :m +Data.Generics.Product.Fields
5757-- >>> :m +Data.Function
5858-- >>> :{
src/Data/Generics/Sum/Typed.hs+1−1
@@ -47,7 +47,7 @@ import Data.Generics.Internal.Profunctor.Prism (prismPRavel)
4747-- >>> :set -XDataKinds
4848-- >>> :set -XDeriveGeneric
4949-- >>> import GHC.Generics
50−-- >>> :m +Data.Generics.Internal.Lens
50+-- >>> :m +Data.Generics.Internal.VL.Prism
5151-- >>> :{
5252-- data Animal
5353-- = Dog Dog