| 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.
- 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 :: * -> *)
- 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' #
Converts a universal lens instance back into a polymorphic lens.
cloneTraversal :: Applicative f => ATraversal a a' b b' -> LensLike f a a' b b' #
Converts a universal traversal instance back into a polymorphic traversal.
cloneSetter :: Identical f => ASetter a a' b b' -> LensLike f a a' b b' #
Converts a universal setter instance back into a polymorphic setter.
cloneGetter :: Phantom f => AGetter a a' b b' -> LensLike f a a' b b' #
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' #
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' #
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' #
ATraversal a a' b b' is a universal Traversal a a' b b' instance
type ATraversal' a b = LensLike' (IKleeneStore b b) a b #
ATraversal' a b is a universal Traversal' a b instance
type AGetter a a' b b' = FoldLike b a a' b b' #
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' #
AFold a a' b b' is a universal Fold' a a' b b' instance
data IKleeneStore b b' a #
Instances
| Functor (IKleeneStore b b') # | |
| Applicative (IKleeneStore b b') # | |
Re-exports
class Functor f => Applicative (f :: * -> *) #
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:
(
<*>) = liftA2 idliftA2 f 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: 2.1 |
| Applicative Maybe | Since: 2.1 |
| Applicative IO | Since: 2.1 |
| Applicative Par1 | Since: 4.9.0.0 |
| Applicative ZipList | f '<$>' 'ZipList' xs1 '<*>' ... '<*>' 'ZipList' xsN
|
| Applicative Identity | Since: 4.8.0.0 |
| Applicative Dual | Since: 4.8.0.0 |
| Applicative Sum | Since: 4.8.0.0 |
| Applicative Product | Since: 4.8.0.0 |
| Applicative First | |
| Applicative Last | |
| Applicative (Either e) | Since: 3.0 |
| Applicative (U1 *) | Since: 4.9.0.0 |
| Monoid a => Applicative ((,) a) | For tuples, the ("hello ", (+15)) <*> ("world!", 2002)
("hello world!",2017)Since: 2.1 |
| Monad m => Applicative (WrappedMonad m) | Since: 2.1 |
| Arrow a => Applicative (ArrowMonad a) | Since: 4.6.0.0 |
| Applicative (Proxy *) | Since: 4.7.0.0 |
| Applicative f => Applicative (Rec1 * f) | Since: 4.9.0.0 |
| Arrow a => Applicative (WrappedArrow a b) | Since: 2.1 |
| Monoid m => Applicative (Const * m) | Since: 2.0.1 |
| Applicative f => Applicative (Alt * f) | |
| (Applicative f, Monad f) => Applicative (WhenMissing f x) | Equivalent to |
| Monoid a => Applicative (Constant * a) | |
| (Monoid w, Applicative m) => Applicative (WriterT w m) | |
| (Functor m, Monad m) => Applicative (StateT s m) | |
| (Functor m, Monad m) => Applicative (StateT s m) | |
| Applicative f => Applicative (Backwards * f) | Apply |
| (Monoid c, Monad m) => Applicative (Zooming m c) # | |
| Applicative (IKleeneStore b b') # | |
| Applicative ((->) LiftedRep LiftedRep a) | Since: 2.1 |
| (Applicative f, Applicative g) => Applicative ((:*:) * f g) | Since: 4.9.0.0 |
| (Monad f, Applicative f) => Applicative (WhenMatched f x y) | Equivalent to |
| (Applicative f, Monad f) => Applicative (WhenMissing f k x) | Equivalent to |
| Applicative f => Applicative (M1 * i c f) | Since: 4.9.0.0 |
| (Applicative f, Applicative g) => Applicative ((:.:) * * f g) | Since: 4.9.0.0 |
| (Applicative f, Applicative g) => Applicative (Compose * * f g) | Since: 4.9.0.0 |
| (Monad f, Applicative f) => Applicative (WhenMatched f k x y) | Equivalent to |