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 (<$) :: a -> IKleeneStore b b' b0 -> IKleeneStore b b' a | |
Applicative (IKleeneStore b b') Source # | |
Defined in Lens.Family.Clone Methods pure :: a -> IKleeneStore b b' a (<*>) :: IKleeneStore b b' (a -> b0) -> IKleeneStore b b' a -> IKleeneStore b b' b0 liftA2 :: (a -> b0 -> c) -> IKleeneStore b b' a -> IKleeneStore b b' b0 -> IKleeneStore b b' c (*>) :: IKleeneStore b b' a -> IKleeneStore b b' b0 -> IKleeneStore b b' b0 (<*) :: IKleeneStore b b' a -> IKleeneStore b b' b0 -> IKleeneStore b b' a |
Re-exports
class Functor f => Applicative (f :: Type -> Type) #
Minimal complete definition
pure, ((<*>) | liftA2)
Instances
Applicative [] | |
Applicative Maybe | |
Applicative IO | |
Applicative Par1 | |
Applicative Product | |
Applicative Sum | |
Applicative P | |
Applicative Identity | |
Applicative NonEmpty | |
Applicative Dual | |
Applicative ZipList | |
Applicative ReadP | |
Applicative First | |
Applicative Last | |
Applicative Down | |
Applicative (Either e) | |
Applicative (U1 :: Type -> Type) | |
Monoid a => Applicative ((,) a) | |
Monad m => Applicative (WrappedMonad m) | |
Defined in Control.Applicative Methods pure :: a -> WrappedMonad m a (<*>) :: WrappedMonad m (a -> b) -> WrappedMonad m a -> WrappedMonad m b liftA2 :: (a -> b -> c) -> WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m c (*>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b (<*) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m a | |
Arrow a => Applicative (ArrowMonad a) | |
Defined in Control.Arrow Methods pure :: a0 -> ArrowMonad a a0 (<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c (*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b (<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 | |
Applicative (Proxy :: Type -> Type) | |
Applicative f => Applicative (Rec1 f) | |
Applicative f => Applicative (Backwards f) | |
Defined in Control.Applicative.Backwards | |
Arrow a => Applicative (WrappedArrow a b) | |
Defined in Control.Applicative Methods pure :: a0 -> WrappedArrow a b a0 (<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c (*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 (<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 | |
Monoid m => Applicative (Const m :: Type -> Type) | |
Monoid a => Applicative (Constant a :: Type -> Type) | |
Defined in Data.Functor.Constant | |
Applicative f => Applicative (Ap f) | |
Applicative f => Applicative (Alt f) | |
(Monoid c, Monad m) => Applicative (Zooming m c) Source # | |
Defined in Lens.Family.State.Zoom | |
(Applicative f, Monad f) => Applicative (WhenMissing f x) | |
Defined in Data.IntMap.Internal Methods pure :: a -> WhenMissing f x a (<*>) :: WhenMissing f x (a -> b) -> WhenMissing f x a -> WhenMissing f x b liftA2 :: (a -> b -> c) -> WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x c (*>) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x b (<*) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x a | |
(Monoid w, Applicative m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Lazy | |
(Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
(Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Lazy | |
Applicative (IKleeneStore b b') Source # | |
Defined in Lens.Family.Clone Methods pure :: a -> IKleeneStore b b' a (<*>) :: IKleeneStore b b' (a -> b0) -> IKleeneStore b b' a -> IKleeneStore b b' b0 liftA2 :: (a -> b0 -> c) -> IKleeneStore b b' a -> IKleeneStore b b' b0 -> IKleeneStore b b' c (*>) :: IKleeneStore b b' a -> IKleeneStore b b' b0 -> IKleeneStore b b' b0 (<*) :: IKleeneStore b b' a -> IKleeneStore b b' b0 -> IKleeneStore b b' a | |
Applicative ((->) a :: Type -> Type) | |
Monoid c => Applicative (K1 i c :: Type -> Type) | |
(Applicative f, Applicative g) => Applicative (f :*: g) | |
(Applicative f, Monad f) => Applicative (WhenMissing f k x) | |
Defined in Data.Map.Internal Methods pure :: a -> WhenMissing f k x a (<*>) :: WhenMissing f k x (a -> b) -> WhenMissing f k x a -> WhenMissing f k x b liftA2 :: (a -> b -> c) -> WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x c (*>) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x b (<*) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x a | |
(Monad f, Applicative f) => Applicative (WhenMatched f x y) | |
Defined in Data.IntMap.Internal Methods pure :: a -> WhenMatched f x y a (<*>) :: WhenMatched f x y (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b liftA2 :: (a -> b -> c) -> WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y c (*>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b (<*) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y a | |
Applicative f => Applicative (M1 i c f) | |
(Applicative f, Applicative g) => Applicative (f :.: g) | |
(Applicative f, Applicative g) => Applicative (Compose f g) | |
Defined in Data.Functor.Compose | |
(Monad f, Applicative f) => Applicative (WhenMatched f k x y) | |
Defined in Data.Map.Internal Methods pure :: a -> WhenMatched f k x y a (<*>) :: WhenMatched f k x y (a -> b) -> WhenMatched f k x y a -> WhenMatched f k x y b liftA2 :: (a -> b -> c) -> WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y c (*>) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y b (<*) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y a |
class Functor f => Phantom f Source #
Minimal complete definition
coerce
Instances
Phantom f => Phantom (Backwards f) Source # | |
Defined in Lens.Family.Phantom | |
Phantom (Const a :: Type -> Type) Source # | |
Defined in Lens.Family.Phantom Methods coerce :: Const a a0 -> Const a b | |
Phantom (Constant a :: Type -> Type) 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 Methods coerce :: Compose f g a -> Compose f g b |
class Applicative f => Identical f Source #
Minimal complete definition
extract