lens 4.1 → 4.1.1
raw patch · 6 files changed
+32/−16 lines, 6 filesdep ~basedep ~distributive
Dependency ranges changed: base, distributive
Files
- CHANGELOG.markdown +5/−0
- lens.cabal +3/−1
- src/Control/Lens/Combinators.hs +0/−1
- src/Control/Lens/Equality.hs +10/−0
- src/Control/Lens/Iso.hs +6/−13
- src/Control/Lens/Plated.hs +8/−1
CHANGELOG.markdown view
@@ -1,3 +1,8 @@+4.1.1+----+* Generalized the types of `mapping`, `bimapping`, `contramapping`, `dimapping`, `lmapping`, `rmapping` to support changing the `Functor`, `Bifunctor`, `Contravariant`, and `Profunctor` respectively.+* Compatibility with `free` 4.6+ 4.1 --- * Added `Plated` instances for various free monad variants.
lens.cabal view
@@ -1,6 +1,6 @@ name: lens category: Data, Lenses, Generics-version: 4.1+version: 4.1.1 license: BSD3 cabal-version: >= 1.8 license-file: LICENSE@@ -304,6 +304,8 @@ other-modules: Control.Lens.Internal.TupleIxedTH++ cpp-options: -traditional if flag(safe) cpp-options: -DSAFE=1
src/Control/Lens/Combinators.hs view
@@ -1,4 +1,3 @@- -------------------------------------------------------------------------------- -- | -- Module : Control.Lens.Combinators
src/Control/Lens/Equality.hs view
@@ -22,6 +22,8 @@ , mapEq , fromEq , simply+ -- * The Trivial Equality+ , simple -- * Implementation Details , Identical(..) ) where@@ -77,3 +79,11 @@ simply :: (Optic' p f s a -> r) -> Optic' p f s a -> r simply = id {-# INLINE simply #-}++-- | Composition with this isomorphism is occasionally useful when your 'Lens',+-- 'Control.Lens.Traversal.Traversal' or 'Iso' has a constraint on an unused+-- argument to force that argument to agree with the+-- type of a used argument and avoid @ScopedTypeVariables@ or other ugliness.+simple :: Equality' a a+simple = id+{-# INLINE simple #-}
src/Control/Lens/Iso.hs view
@@ -62,6 +62,7 @@ , bimapping ) where +import Control.Lens.Equality (simple) import Control.Lens.Fold import Control.Lens.Internal.Context import Control.Lens.Internal.Indexed@@ -215,18 +216,10 @@ {-# INLINE enum #-} -- | This can be used to lift any 'Iso' into an arbitrary 'Functor'.-mapping :: Functor f => AnIso s t a b -> Iso (f s) (f t) (f a) (f b)+mapping :: (Functor f, Functor g) => AnIso s t a b -> Iso (f s) (g t) (f a) (g b) mapping k = withIso k $ \ sa bt -> iso (fmap sa) (fmap bt) {-# INLINE mapping #-} --- | Composition with this isomorphism is occasionally useful when your 'Lens',--- 'Control.Lens.Traversal.Traversal' or 'Iso' has a constraint on an unused--- argument to force that argument to agree with the--- type of a used argument and avoid @ScopedTypeVariables@ or other ugliness.-simple :: Iso' a a-simple = id-{-# INLINE simple #-}- -- | If @v@ is an element of a type @a@, and @a'@ is @a@ sans the element @v@, then @'non' v@ is an isomorphism from -- @'Maybe' a'@ to @a@. --@@ -464,7 +457,7 @@ -- dimapping :: 'Profunctor' p => 'Iso' s t a b -> 'Iso' s' t' a' b' -> 'Iso' (p a s') (p b t') (p s a') (p t b') -- dimapping :: 'Profunctor' p => 'Iso'' s a -> 'Iso'' s' a' -> 'Iso'' (p a s') (p s a') -- @-dimapping :: Profunctor p => AnIso s t a b -> AnIso s' t' a' b' -> Iso (p a s') (p b t') (p s a') (p t b')+dimapping :: (Profunctor p, Profunctor q) => AnIso s t a b -> AnIso s' t' a' b' -> Iso (p a s') (q b t') (p s a') (q t b') dimapping f g = withIso f $ \ sa bt -> withIso g $ \ s'a' b't' -> iso (dimap sa s'a') (dimap bt b't') {-# INLINE dimapping #-}@@ -475,7 +468,7 @@ -- lmapping :: 'Profunctor' p => 'Iso' s t a b -> 'Iso' (p a x) (p b y) (p s x) (p t y) -- lmapping :: 'Profunctor' p => 'Iso'' s a -> 'Iso'' (p a x) (p s x) -- @-lmapping :: Profunctor p => AnIso s t a b -> Iso (p a x) (p b y) (p s x) (p t y)+lmapping :: (Profunctor p, Profunctor q) => AnIso s t a b -> Iso (p a x) (q b y) (p s x) (q t y) lmapping f = withIso f $ \ sa bt -> iso (lmap sa) (lmap bt) {-# INLINE lmapping #-} @@ -485,7 +478,7 @@ -- rmapping :: 'Profunctor' p => 'Iso' s t a b -> 'Iso' (p x s) (p y t) (p x a) (p y b) -- rmapping :: 'Profunctor' p => 'Iso'' s a -> 'Iso'' (p x s) (p x a) -- @-rmapping :: Profunctor p => AnIso s t a b -> Iso (p x s) (p y t) (p x a) (p y b)+rmapping :: (Profunctor p, Profunctor q) => AnIso s t a b -> Iso (p x s) (q y t) (p x a) (q y b) rmapping g = withIso g $ \ sa bt -> iso (rmap sa) (rmap bt) {-# INLINE rmapping #-} @@ -499,7 +492,7 @@ -- bimapping :: 'Profunctor' p => 'Iso' s t a b -> 'Iso' s' t' a' b' -> 'Iso' (p s s') (p t t') (p a a') (p b b') -- bimapping :: 'Profunctor' p => 'Iso'' s a -> 'Iso'' s' a' -> 'Iso'' (p s s') (p a a') -- @-bimapping :: Bifunctor f => AnIso s t a b -> AnIso s' t' a' b' -> Iso (f s s') (f t t') (f a a') (f b b')+bimapping :: (Bifunctor f, Bifunctor g) => AnIso s t a b -> AnIso s' t' a' b' -> Iso (f s s') (g t t') (f a a') (g b b') bimapping f g = withIso f $ \ sa bt -> withIso g $ \s'a' b't' -> iso (bimap sa s'a') (bimap bt b't') {-# INLINE bimapping #-}
src/Control/Lens/Plated.hs view
@@ -12,6 +12,10 @@ #ifndef MIN_VERSION_template_haskell #define MIN_VERSION_template_haskell(x,y,z) 1 #endif++#ifndef MIN_VERSION_free+#define MIN_VERSION_free(x,y,z) 1+#endif ------------------------------------------------------------------------------- -- | -- Module : Control.Lens.Plated@@ -91,8 +95,9 @@ import Control.Monad.Free as Monad import Control.Monad.Free.Church as Church import Control.Monad.Trans.Free as Trans--- import Control.Monad.Trans.Free.Church as ChurchT+#if !(MIN_VERSION_free(4,6,0)) import Control.MonadPlus.Free as MonadPlus+#endif import qualified Language.Haskell.TH as TH import Data.Aeson import Data.Bitraversable@@ -216,10 +221,12 @@ instance (Traversable f, Traversable m) => Plated (Trans.FreeT f m a) where plate f (Trans.FreeT xs) = Trans.FreeT <$> traverse (bitraverse pure f) xs +#if !(MIN_VERSION_free(4,6,0)) instance Traversable f => Plated (MonadPlus.Free f a) where plate f (MonadPlus.Free as) = MonadPlus.Free <$> traverse f as plate f (MonadPlus.Plus as) = MonadPlus.Plus <$> traverse f as plate _ x = pure x+#endif instance Traversable f => Plated (Church.F f a) where plate f = fmap Church.toF . plate (fmap Church.fromF . f . Church.toF) . Church.fromF