@@ -23,8 +23,7 @@ module Data.Generics.Internal.VL.Lens where
24import Control.Applicative (Const(..))
24import Control.Applicative (Const(..))
25import Data.Functor.Identity (Identity(..))
25import Data.Functor.Identity (Identity(..))
26−import Data.Generics.Internal.Profunctor.Lens (ALens (..), (^.), idLens)
26+import Data.Generics.Internal.Profunctor.Lens (ALens (..), idLens)
27−import GHC.Exts (inline, oneShot)
29-- | Type alias for lens
28-- | Type alias for lens
30type Lens' s a
29type Lens' s a
@@ -36,8 +35,17 @@ type Lens s t a b
36view :: ((a -> Const a a) -> s -> Const a s) -> s -> a
35view :: ((a -> Const a a) -> s -> Const a s) -> s -> a
37view l s = (^.) s l
36view l s = (^.) s l
39+(^.) :: s -> ((a -> Const a a) -> s -> Const a s) -> a
40+s ^. l = getConst (l Const s)
44+(.~) :: ((a -> Identity b) -> s -> Identity t) -> b -> s -> t
45+(.~) f b = runIdentity . f (Identity . const b)
39set :: Lens s t a b -> b -> s -> t
47set :: Lens s t a b -> b -> s -> t
40−set l x = runIdentity . l (Identity . const x)
48+set l x = l .~ x
42lens2lensvl :: ALens a b s t -> Lens s t a b
50lens2lensvl :: ALens a b s t -> Lens s t a b
43lens2lensvl (ALens _get _set) =
51lens2lensvl (ALens _get _set) =
@@ -50,6 +58,7 @@ ravel :: (ALens a b a b -> ALens a b s t)
50 -> Lens s t a b
58 -> Lens s t a b
51ravel l pab = (lens2lensvl $ l idLens) pab
59ravel l pab = (lens2lensvl $ l idLens) pab
53lens :: (s -> a) -> ((s, b) -> t) -> Lens s t a b
62lens :: (s -> a) -> ((s, b) -> t) -> Lens s t a b
54lens get _set = \f x -> curry _set x <$> f (get x)
63lens get _set = \f x -> curry _set x <$> f (get x)
55{-# INLINE[0] lens #-}
64{-# INLINE[0] lens #-}