| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Lens.Family.Clone
Contents
Description
This module is provided for "Haskell 2022" compatibility.
If you are able to use Rank2Types, I advise you to instead use the rank 2 aliases
Adapter,Adapter'Prism,Prism'Lens,Lens'Traversal,Traversal'Setter,Setter'Grate,Grate'Resetter,Resetter'Grid,Grid'Fold,Fold'Getter,Getter'Reviewer,Reviewer'
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 s t a b).
Then, inside a ALens' s awhere clause, you use cloneLens to create a Lens type.
For example.
example :: ALens s t a 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.
cloneAdapter, cloneGrate, cloneTraversal, cloneSetter, cloneResetter, cloneGetter, and cloneFold provides similar functionality for adapters, grates, traversals, setters, resetters, getters, and folds respectively. Unfortunately, it is not yet known how to clone prisms and grids.
Note: Cloning is only need if you use a functional reference multiple times with different instances.
Synopsis
- cloneAdapter :: (Functor f, Functor g) => AnAdapter s t a b -> AdapterLike f g s t a b
- cloneLens :: Functor f => ALens s t a b -> LensLike f s t a b
- cloneGrate :: Functor g => AGrate s t a b -> GrateLike g s t a b
- cloneTraversal :: Applicative f => ATraversal s t a b -> LensLike f s t a b
- cloneSetter :: Identical f => ASetter s t a b -> LensLike f s t a b
- cloneResetter :: Identical f => AResetter s t a b -> GrateLike f s t a b
- cloneGetter :: Phantom f => AGetter s t a b -> LensLike f s t a b
- cloneFold :: (Phantom f, Applicative f) => AFold s t a b -> LensLike f s t a b
- type AnAdapter s t a b = AdapterLike (PStore (s -> a) b) ((->) s) s t a b
- type AnAdapter' s a = AdapterLike' (PStore (s -> a) a) ((->) s) s a
- type ALens s t a b = LensLike (PStore a b) s t a b
- type ALens' s a = LensLike' (PStore a a) s a
- type ATraversal s t a b = LensLike (PKleeneStore a b) s t a b
- type ATraversal' s a = LensLike' (PKleeneStore a a) s a
- type AGetter s t a b = FoldLike a s t a b
- type AGetter' s a = FoldLike' a s a
- type AFold s t a b = FoldLike [a] s t a b
- type AFold' s a = FoldLike' [a] s a
- data PStore i j a
- data PKleeneStore i j a
- type LensLike f s t a b = (a -> f b) -> s -> f t
- type LensLike' f s a = (a -> f a) -> s -> f s
- type GrateLike g s t a b = (g a -> b) -> g s -> t
- type GrateLike' g s a = (g a -> a) -> g s -> s
- type FoldLike r s t a b = LensLike (Constant r) s t a b
- type FoldLike' r s a = LensLike' (Constant r) s a
- type AGrate s t a b = GrateLike (PCont b a) s t a b
- type ASetter s t a b = LensLike Identity s t a b
- type AResetter s t a b = GrateLike Identity s t a b
- class Functor f => Phantom f
- class (Traversable f, Applicative f) => Identical f
Documentation
cloneAdapter :: (Functor f, Functor g) => AnAdapter s t a b -> AdapterLike f g s t a b Source #
Converts a universal adapter instance back into a polymorphic adapter.
cloneLens :: Functor f => ALens s t a b -> LensLike f s t a b Source #
Converts a universal lens instance back into a polymorphic lens.
cloneGrate :: Functor g => AGrate s t a b -> GrateLike g s t a b Source #
Converts a universal grate instance back into a polymorphic grater.
cloneTraversal :: Applicative f => ATraversal s t a b -> LensLike f s t a b Source #
Converts a universal traversal instance back into a polymorphic traversal.
cloneSetter :: Identical f => ASetter s t a b -> LensLike f s t a b Source #
Converts a universal setter instance back into a polymorphic setter.
cloneResetter :: Identical f => AResetter s t a b -> GrateLike f s t a b Source #
Converts a universal resetter instance back into a polymorphic resetter.
cloneGetter :: Phantom f => AGetter s t a b -> LensLike f s t a b Source #
Converts a universal getter instance back into a polymorphic getter.
cloneFold :: (Phantom f, Applicative f) => AFold s t a b -> LensLike f s t a b Source #
Converts a universal fold instance back into a polymorphic fold.
Types
type AnAdapter s t a b = AdapterLike (PStore (s -> a) b) ((->) s) s t a b Source #
AnAdapter s t a b is a universal Adapter s t a b instance
type AnAdapter' s a = AdapterLike' (PStore (s -> a) a) ((->) s) s a Source #
AnAdapter' s a is a universal Adapter' s a instance
type ALens s t a b = LensLike (PStore a b) s t a b Source #
ALens s t a b is a universal Lens s t a b instance
type ATraversal s t a b = LensLike (PKleeneStore a b) s t a b Source #
ATraversal s t a b is a universal Traversal s t a b instance
type ATraversal' s a = LensLike' (PKleeneStore a a) s a Source #
ATraversal' a b is a universal Traversal' a b instance
type AGetter s t a b = FoldLike a s t a b Source #
AGetter s t a b is a universal Getter s t a b instance
type AFold s t a b = FoldLike [a] s t a b Source #
AFold s t a b is a universal Fold s t a b instance
data PKleeneStore i j a Source #
Instances
| Applicative (PKleeneStore i j) Source # | |
Defined in Lens.Family.Clone Methods pure :: a -> PKleeneStore i j a # (<*>) :: PKleeneStore i j (a -> b) -> PKleeneStore i j a -> PKleeneStore i j b # liftA2 :: (a -> b -> c) -> PKleeneStore i j a -> PKleeneStore i j b -> PKleeneStore i j c # (*>) :: PKleeneStore i j a -> PKleeneStore i j b -> PKleeneStore i j b # (<*) :: PKleeneStore i j a -> PKleeneStore i j b -> PKleeneStore i j a # | |
| Functor (PKleeneStore i j) Source # | |
Defined in Lens.Family.Clone Methods fmap :: (a -> b) -> PKleeneStore i j a -> PKleeneStore i j b # (<$) :: a -> PKleeneStore i j b -> PKleeneStore i j a # | |
Re-exports
type GrateLike' g s a = (g a -> a) -> g s -> s Source #
class Functor f => Phantom f Source #
Minimal complete definition
coerce
Instances
| Phantom (Const a :: Type -> Type) Source # | |
Defined in Lens.Family.Phantom | |
| Phantom f => Phantom (AlongsideLeft f a) Source # | |
Defined in Lens.Family.Stock Methods coerce :: AlongsideLeft f a a0 -> AlongsideLeft f a b | |
| Phantom f => Phantom (AlongsideRight f a) Source # | |
Defined in Lens.Family.Stock Methods coerce :: AlongsideRight f a a0 -> AlongsideRight f a b | |
| Phantom g => Phantom (FromG e g) Source # | |
Defined in Lens.Family.Stock | |
| Phantom f => Phantom (Backwards f) Source # | |
Defined in Lens.Family.Phantom | |
| Phantom (Constant a :: Type -> Type) Source # | |
Defined in Lens.Family.Phantom | |
| Phantom g => Phantom (FromF i j g) Source # | |
Defined in Lens.Family.Stock | |
| (Phantom f, Functor g) => Phantom (Compose f g) Source # | |
Defined in Lens.Family.Phantom | |
class (Traversable f, Applicative f) => Identical f Source #
Minimal complete definition
extract