@@ -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 #-}