Permalink
Browse files

renaming ^%%= to fmodL and fmodML.

Removing ^%%= for partial lens.  Instead promote the partiallens to a multilens and use fmodML.
  • Loading branch information...
1 parent d91d5dc commit 3af3d68dfe04ca52d3c63274436fa025ca1455d9 @roconnor committed Jun 9, 2012
Showing with 11 additions and 21 deletions.
  1. +5 −7 src/Data/Lens/Common.hs
  2. +6 −7 src/Data/Lens/Multi/Common.hs
  3. +0 −7 src/Data/Lens/Partial/Common.hs
View
@@ -7,14 +7,14 @@ module Data.Lens.Common
, getL
, setL
, modL
+ , fmodL
, mergeL
, unzipL
-- * Operator API
, (^$), (^$!) -- getter -- :: Lens a b -> a -> b
, (^.), (^!) -- getter -- :: a -> Lens a b -> b
, (^=), (^!=) -- setter -- :: Lens a b -> b -> (a -> a)
, (^%=), (^!%=) -- modify -- :: Lens a b -> (b -> b) -> (a -> a)
- , (^%%=) -- modify -- :: Functor f => Lens a b -> (b -> f b) -> a -> f a
-- * Pseudo-imperatives
, (^+=), (^!+=) -- addition
, (^-=), (^!-=) -- subtraction
@@ -98,6 +98,10 @@ Lens f ^!= b = \a -> case f a of
modL :: Lens a b -> (b -> b) -> a -> a
modL (Lens f) g = peeks g . f
+fmodL :: Functor f => Lens a b -> (b -> f b) -> a -> f a
+fmodL (Lens f) g = \a -> case f a of
+ StoreT (Identity h) b -> h <$> g b
+
mergeL :: Lens a c -> Lens b c -> Lens (Either a b) c
Lens f `mergeL` Lens g =
Lens $ either (\a -> Left <$> f a) (\b -> Right <$> g b)
@@ -112,12 +116,6 @@ infixr 4 ^%=, ^!%=
Lens f ^!%= g = \a -> case f a of
StoreT (Identity h) b -> h $! g b
-infixr 4 ^%%=
--- | functorial modify
-(^%%=) :: Functor f => Lens a b -> (b -> f b) -> a -> f a
-Lens f ^%%= g = \a -> case f a of
- StoreT (Identity h) b -> h <$> g b
-
infixr 4 ^+=, ^!+=, ^-=, ^!-=, ^*=, ^!*=
(^+=), (^!+=), (^-=), (^!-=), (^*=), (^!*=) :: Num b => Lens a b -> b -> a -> a
l ^+= n = l ^%= (+ n)
@@ -18,7 +18,7 @@ newtype MultiLens a b = MLens {runMLens :: a -> StaredStore b a}
instance Category MultiLens where
id = totalML id
- MLens f . g = MLens $ g ^%%= f
+ MLens f . g = MLens $ g `fmodML` f
-- totalLens is a homomorphism of categories; ie a functor.
totalML :: Lens a b -> MultiLens a b
@@ -34,19 +34,18 @@ getML (MLens f) = poss . f
modML :: MultiLens a b -> (b -> b) -> a -> a
modML (MLens f) g = peekss g . f
-infixr 4 ^%%=
-- | applicative modify
--- (id ^%%= h) = h
--- (f . g) ^%%= h) = (g ^%%= (f ^%%= h))
-(^%%=) :: Applicative f => MultiLens a b -> (b -> f b) -> a -> f a
-MLens f ^%%= g = eekss g . f
+-- (id `fmodML` h) = h
+-- ((f . g) `fmodML` h) = g `amodL` (f `amodL` h))
+fmodML :: Applicative f => MultiLens a b -> (b -> f b) -> a -> f a
+MLens f `fmodML` g = eekss g . f
frontPL :: MultiLens a b -> PartialLens a b
frontPL (MLens f) = pLens $
coproduct left (right . uncurry store . (extract *** id) . runStoreT) . runStaredStore . f
reverseML :: MultiLens a b -> MultiLens a b
-reverseML l = MLens (forwards . (l ^%%= (Backwards . runMLens id)))
+reverseML l = MLens (forwards . (l `fmodML` (Backwards . runMLens id)))
backPL :: MultiLens a b -> PartialLens a b
backPL = frontPL . reverseML
@@ -110,13 +110,6 @@ infixr 4 ^%=
(^%=) :: PartialLens a b -> (b -> b) -> a -> a
(^%=) = modPL
-infixr 4 ^%%=
--- | applicative modify
-(^%%=) :: Applicative f => PartialLens a b -> (b -> f b) -> a -> f a
-PLens f ^%%= g = \a -> case f a of
- Nothing -> pure a
- Just (StoreT (Identity h) b) -> h <$> g b
-
-- * Pseudo-imperatives
infixr 4 ^+=, ^-=, ^*=

0 comments on commit 3af3d68

Please sign in to comment.