| Safe Haskell | Safe |
|---|---|
| Language | Haskell98 |
Lens.Family.Clone
Contents
Description
This module is provided for Haskell 98 compatibility.
If you are able to use Rank2Types, I advise you to instead use the rank 2 aliases
Lens,Lens'Traversal,Traversal'Setter,Setter'Fold,Fold'Getter,Getter'
from the lens-family package instead.
cloneLens allows one to circumvent the need for rank 2 types by allowing one to take a universal monomorphic lens instance and rederive a polymorphic instance.
When you require a lens family parameter you use the type (or ALens a a' b b').
Then, inside a ALens' a bwhere clause, you use cloneLens to create a Lens type.
For example.
example :: ALens a a' b b' -> Example example l = ... x^.cl ... cl .~ y ... where cl x = cloneLens l x
Note: It is important to eta-expand the definition of cl to avoid the dreaded monomorphism restriction.
cloneTraversal, cloneGetter, cloneSetter, and cloneFold provides similar functionality for traversals, getters, setters, and folds respectively.
Note: Cloning is only need if you use a functional reference multiple times with different instances.
Synopsis
- cloneLens :: Functor f => ALens a a' b b' -> LensLike f a a' b b'
- cloneTraversal :: Applicative f => ATraversal a a' b b' -> LensLike f a a' b b'
- cloneSetter :: Identical f => ASetter a a' b b' -> LensLike f a a' b b'
- cloneGetter :: Phantom f => AGetter a a' b b' -> LensLike f a a' b b'
- cloneFold :: (Phantom f, Applicative f) => AFold a a' b b' -> LensLike f a a' b b'
- type ALens a a' b b' = LensLike (IStore b b') a a' b b'
- type ALens' a b = LensLike' (IStore b b) a b
- type ATraversal a a' b b' = LensLike (IKleeneStore b b') a a' b b'
- type ATraversal' a b = LensLike' (IKleeneStore b b) a b
- type AGetter a a' b b' = FoldLike b a a' b b'
- type AGetter' a b = FoldLike' b a b
- type AFold a a' b b' = FoldLike [b] a a' b b'
- type AFold' a b = FoldLike' [b] a b
- data IStore b b' a
- data IKleeneStore b b' a
- type LensLike f a a' b b' = (b -> f b') -> a -> f a'
- type LensLike' f a b = (b -> f b) -> a -> f a
- type FoldLike r a a' b b' = LensLike (Constant r) a a' b b'
- type FoldLike' r a b = LensLike' (Constant r) a b
- type ASetter a a' b b' = LensLike Identity a a' b b'
- class Functor f => Applicative (f :: Type -> Type)
- class Functor f => Phantom f
- class Applicative f => Identical f
Documentation
cloneLens :: Functor f => ALens a a' b b' -> LensLike f a a' b b' Source #
Converts a universal lens instance back into a polymorphic lens.
cloneTraversal :: Applicative f => ATraversal a a' b b' -> LensLike f a a' b b' Source #
Converts a universal traversal instance back into a polymorphic traversal.
cloneSetter :: Identical f => ASetter a a' b b' -> LensLike f a a' b b' Source #
Converts a universal setter instance back into a polymorphic setter.
cloneGetter :: Phantom f => AGetter a a' b b' -> LensLike f a a' b b' Source #
Converts a universal getter instance back into a polymorphic getter.
cloneFold :: (Phantom f, Applicative f) => AFold a a' b b' -> LensLike f a a' b b' Source #
Converts a universal fold instance back into a polymorphic fold.
Types
type ALens a a' b b' = LensLike (IStore b b') a a' b b' Source #
ALens a a' b b' is a universal Lens a a' b b' instance
type ATraversal a a' b b' = LensLike (IKleeneStore b b') a a' b b' Source #
ATraversal a a' b b' is a universal Traversal a a' b b' instance
type ATraversal' a b = LensLike' (IKleeneStore b b) a b Source #
ATraversal' a b is a universal Traversal' a b instance
type AGetter a a' b b' = FoldLike b a a' b b' Source #
AGetter a a' b b' is a universal Fold a a' b b' instance
type AFold a a' b b' = FoldLike [b] a a' b b' Source #
AFold a a' b b' is a universal Fold' a a' b b' instance
data IKleeneStore b b' a Source #
Instances
| Functor (IKleeneStore b b') Source # | |
Defined in Lens.Family.Clone Methods fmap :: (a -> b0) -> IKleeneStore b b' a -> IKleeneStore b b' b0 Source # (<$) :: a -> IKleeneStore b b' b0 -> IKleeneStore b b' a Source # | |
| Applicative (IKleeneStore b b') Source # | |
Defined in Lens.Family.Clone Methods pure :: a -> IKleeneStore b b' a Source # (<*>) :: IKleeneStore b b' (a -> b0) -> IKleeneStore b b' a -> IKleeneStore b b' b0 Source # liftA2 :: (a -> b0 -> c) -> IKleeneStore b b' a -> IKleeneStore b b' b0 -> IKleeneStore b b' c Source # (*>) :: IKleeneStore b b' a -> IKleeneStore b b' b0 -> IKleeneStore b b' b0 Source # (<*) :: IKleeneStore b b' a -> IKleeneStore b b' b0 -> IKleeneStore b b' a Source # | |
Re-exports
class Functor f => Applicative (f :: Type -> Type) Source #
A functor with application, providing operations to
A minimal complete definition must include implementations of pure
and of either <*> or liftA2. If it defines both, then they must behave
the same as their default definitions:
(<*>) =liftA2id
liftA2f x y = f<$>x<*>y
Further, any definition must satisfy the following:
- identity
pureid<*>v = v- composition
pure(.)<*>u<*>v<*>w = u<*>(v<*>w)- homomorphism
puref<*>purex =pure(f x)- interchange
u
<*>purey =pure($y)<*>u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
As a consequence of these laws, the Functor instance for f will satisfy
It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2p (liftA2q u v) =liftA2f u .liftA2g v
If f is also a Monad, it should satisfy
(which implies that pure and <*> satisfy the applicative functor laws).
Instances
| Applicative [] | Since: base-2.1 |
| Applicative Maybe | Since: base-2.1 |
| Applicative IO | Since: base-2.1 |
| Applicative Par1 | Since: base-4.9.0.0 |
| Applicative ZipList | f '<$>' 'ZipList' xs1 '<*>' ... '<*>' 'ZipList' xsN
= 'ZipList' (zipWithN f xs1 ... xsN)where (\a b c -> stimes c [a, b]) <$> ZipList "abcd" <*> ZipList "567" <*> ZipList [1..]
= ZipList (zipWith3 (\a b c -> stimes c [a, b]) "abcd" "567" [1..])
= ZipList {getZipList = ["a5","b6b6","c7c7c7"]}Since: base-2.1 |
Defined in Control.Applicative | |
| Applicative Identity | Since: base-4.8.0.0 |
Defined in Data.Functor.Identity | |
| Applicative First | Since: base-4.8.0.0 |
| Applicative Last | Since: base-4.8.0.0 |
| Applicative Dual | Since: base-4.8.0.0 |
| Applicative Sum | Since: base-4.8.0.0 |
| Applicative Product | Since: base-4.8.0.0 |
Defined in Data.Semigroup.Internal | |
| Applicative Down | Since: base-4.11.0.0 |
| Applicative ReadP | Since: base-4.6.0.0 |
| Applicative NonEmpty | Since: base-4.9.0.0 |
Defined in GHC.Base | |
| Applicative P | Since: base-4.5.0.0 |
| Applicative (Either e) | Since: base-3.0 |
Defined in Data.Either | |
| Applicative (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| Monoid a => Applicative ((,) a) | For tuples, the ("hello ", (+15)) <*> ("world!", 2002)
("hello world!",2017)Since: base-2.1 |
| Monad m => Applicative (WrappedMonad m) | Since: base-2.1 |
Defined in Control.Applicative Methods pure :: a -> WrappedMonad m a Source # (<*>) :: WrappedMonad m (a -> b) -> WrappedMonad m a -> WrappedMonad m b Source # liftA2 :: (a -> b -> c) -> WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m c Source # (*>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b Source # (<*) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m a Source # | |
| Arrow a => Applicative (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow Methods pure :: a0 -> ArrowMonad a a0 Source # (<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b Source # liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c Source # (*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b Source # (<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 Source # | |
| Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| Applicative f => Applicative (Rec1 f) | Since: base-4.9.0.0 |
| Arrow a => Applicative (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative Methods pure :: a0 -> WrappedArrow a b a0 Source # (<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 Source # liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c Source # (*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 Source # (<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 Source # | |
| Monoid m => Applicative (Const m :: Type -> Type) | Since: base-2.0.1 |
Defined in Data.Functor.Const | |
| Applicative f => Applicative (Ap f) | Since: base-4.12.0.0 |
| Applicative f => Applicative (Alt f) | Since: base-4.8.0.0 |
| (Applicative f, Monad f) => Applicative (WhenMissing f x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods pure :: a -> WhenMissing f x a Source # (<*>) :: WhenMissing f x (a -> b) -> WhenMissing f x a -> WhenMissing f x b Source # liftA2 :: (a -> b -> c) -> WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x c Source # (*>) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x b Source # (<*) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x a Source # | |
| Monoid a => Applicative (Constant a :: Type -> Type) | |
Defined in Data.Functor.Constant Methods pure :: a0 -> Constant a a0 Source # (<*>) :: Constant a (a0 -> b) -> Constant a a0 -> Constant a b Source # liftA2 :: (a0 -> b -> c) -> Constant a a0 -> Constant a b -> Constant a c Source # (*>) :: Constant a a0 -> Constant a b -> Constant a b Source # (<*) :: Constant a a0 -> Constant a b -> Constant a a0 Source # | |
| (Monoid w, Applicative m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Lazy Methods pure :: a -> WriterT w m a Source # (<*>) :: WriterT w m (a -> b) -> WriterT w m a -> WriterT w m b Source # liftA2 :: (a -> b -> c) -> WriterT w m a -> WriterT w m b -> WriterT w m c Source # (*>) :: WriterT w m a -> WriterT w m b -> WriterT w m b Source # (<*) :: WriterT w m a -> WriterT w m b -> WriterT w m a Source # | |
| (Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict Methods pure :: a -> StateT s m a Source # (<*>) :: StateT s m (a -> b) -> StateT s m a -> StateT s m b Source # liftA2 :: (a -> b -> c) -> StateT s m a -> StateT s m b -> StateT s m c Source # (*>) :: StateT s m a -> StateT s m b -> StateT s m b Source # (<*) :: StateT s m a -> StateT s m b -> StateT s m a Source # | |
| (Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Lazy Methods pure :: a -> StateT s m a Source # (<*>) :: StateT s m (a -> b) -> StateT s m a -> StateT s m b Source # liftA2 :: (a -> b -> c) -> StateT s m a -> StateT s m b -> StateT s m c Source # (*>) :: StateT s m a -> StateT s m b -> StateT s m b Source # (<*) :: StateT s m a -> StateT s m b -> StateT s m a Source # | |
| Applicative f => Applicative (Backwards f) | Apply |
Defined in Control.Applicative.Backwards Methods pure :: a -> Backwards f a Source # (<*>) :: Backwards f (a -> b) -> Backwards f a -> Backwards f b Source # liftA2 :: (a -> b -> c) -> Backwards f a -> Backwards f b -> Backwards f c Source # (*>) :: Backwards f a -> Backwards f b -> Backwards f b Source # (<*) :: Backwards f a -> Backwards f b -> Backwards f a Source # | |
| (Monoid c, Monad m) => Applicative (Zooming m c) Source # | |
Defined in Lens.Family.State.Zoom Methods pure :: a -> Zooming m c a Source # (<*>) :: Zooming m c (a -> b) -> Zooming m c a -> Zooming m c b Source # liftA2 :: (a -> b -> c0) -> Zooming m c a -> Zooming m c b -> Zooming m c c0 Source # (*>) :: Zooming m c a -> Zooming m c b -> Zooming m c b Source # (<*) :: Zooming m c a -> Zooming m c b -> Zooming m c a Source # | |
| Applicative (IKleeneStore b b') Source # | |
Defined in Lens.Family.Clone Methods pure :: a -> IKleeneStore b b' a Source # (<*>) :: IKleeneStore b b' (a -> b0) -> IKleeneStore b b' a -> IKleeneStore b b' b0 Source # liftA2 :: (a -> b0 -> c) -> IKleeneStore b b' a -> IKleeneStore b b' b0 -> IKleeneStore b b' c Source # (*>) :: IKleeneStore b b' a -> IKleeneStore b b' b0 -> IKleeneStore b b' b0 Source # (<*) :: IKleeneStore b b' a -> IKleeneStore b b' b0 -> IKleeneStore b b' a Source # | |
| Applicative ((->) a :: Type -> Type) | Since: base-2.1 |
| Monoid c => Applicative (K1 i c :: Type -> Type) | Since: base-4.12.0.0 |
| (Applicative f, Applicative g) => Applicative (f :*: g) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| (Monad f, Applicative f) => Applicative (WhenMatched f x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods pure :: a -> WhenMatched f x y a Source # (<*>) :: WhenMatched f x y (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b Source # liftA2 :: (a -> b -> c) -> WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y c Source # (*>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b Source # (<*) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y a Source # | |
| (Applicative f, Monad f) => Applicative (WhenMissing f k x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods pure :: a -> WhenMissing f k x a Source # (<*>) :: WhenMissing f k x (a -> b) -> WhenMissing f k x a -> WhenMissing f k x b Source # liftA2 :: (a -> b -> c) -> WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x c Source # (*>) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x b Source # (<*) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x a Source # | |
| Applicative f => Applicative (M1 i c f) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| (Applicative f, Applicative g) => Applicative (f :.: g) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| (Applicative f, Applicative g) => Applicative (Compose f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose Methods pure :: a -> Compose f g a Source # (<*>) :: Compose f g (a -> b) -> Compose f g a -> Compose f g b Source # liftA2 :: (a -> b -> c) -> Compose f g a -> Compose f g b -> Compose f g c Source # (*>) :: Compose f g a -> Compose f g b -> Compose f g b Source # (<*) :: Compose f g a -> Compose f g b -> Compose f g a Source # | |
| (Monad f, Applicative f) => Applicative (WhenMatched f k x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods pure :: a -> WhenMatched f k x y a Source # (<*>) :: WhenMatched f k x y (a -> b) -> WhenMatched f k x y a -> WhenMatched f k x y b Source # liftA2 :: (a -> b -> c) -> WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y c Source # (*>) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y b Source # (<*) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y a Source # | |
class Functor f => Phantom f Source #
Minimal complete definition
coerce
Instances
| Phantom (Const a :: Type -> Type) Source # | |
Defined in Lens.Family.Phantom | |
| Phantom (Constant a :: Type -> Type) Source # | |
Defined in Lens.Family.Phantom | |
| Phantom f => Phantom (Backwards f) Source # | |
Defined in Lens.Family.Phantom | |
| Phantom f => Phantom (AlongsideRight f a) Source # | |
Defined in Lens.Family.Stock Methods coerce :: AlongsideRight f a a0 -> AlongsideRight f a b | |
| Phantom f => Phantom (AlongsideLeft f a) Source # | |
Defined in Lens.Family.Stock Methods coerce :: AlongsideLeft f a a0 -> AlongsideLeft f a b | |
| (Phantom f, Functor g) => Phantom (Compose f g) Source # | |
Defined in Lens.Family.Phantom | |
class Applicative f => Identical f Source #
Minimal complete definition
extract