HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulelens-family-core-2.1.3Haskell2010

Lens.Family.Clone

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 ALens s t a b (or ALens' s a). Then, inside a where 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.

  • 21 types
  • 2 classes
  • 8 values

Types

12 declarations
typetype AnAdapter s t a b = AdapterLike (PStore (s -> a) b) ((->) s) s t a b
#

AnAdapter s t a b is a universal Adapter s t a b instance

typetype ALens s t a b = LensLike (PStore a b) s t a b
#

ALens s t a b is a universal Lens s t a b instance

typetype AGetter s t a b = FoldLike a s t a b
#

AGetter s t a b is a universal Getter s t a b instance

typetype AGetter' s a = FoldLike' a s a
#

AGetter' s a is a universal Getter' s a instance

typetype AFold s t a b = FoldLike [a] s t a b
#

AFold s t a b is a universal Fold s t a b instance

typetype AFold' s a = FoldLike' [a] s a
#

AFold' s a is a universal Fold' s a instance

datadata PStore i j a
#
Instances1Functor
  • Functor (PStore i j)Defined in lens-family-core-2.1.3 · Lens.Family.Clone

Re-exports

11 declarations
classclass Functor f => Phantom (f :: Type -> Type) where
#
Instances8Phantom, …