Safe Haskell | Safe-Infered |
---|
This module is only provided for Haskell 98 compatibility.
If you are able to use Rank2Types
, I strongly advise you to instead use LensFamily
and Lens
from the lens-family package instead.
clone
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 ClonerFamily
a a' b b'
).
Then, inside a Cloner
a bwhere
clause, you use clone
to create a LensFamily
type.
For example.
example :: ClonerFamily a a' b b' -> Example example l = ... x ^. cl ... cl ^= y ... where cl x = clone l x
Note: It is important to eta-expand the definition of cl
to avoid the dreaded monomorphism restriction.
Note: Cloning is only need if you use both Getter
s and Setter
s in the function.
Otherwise you only need to use the monomorphic GetterFamily
/ Getter
or SetterFamily
/ Setter
.
- clone :: Functor f => ClonerFamily a a' b b' -> RefFamily f a a' b b'
- type RefFamily f a a' b b' = (b -> f b') -> a -> f a'
- type ClonerFamily a a' b b' = RefFamily (Cloning b' b) a a' b b'
- type Cloner a b = ClonerFamily a a b b
Documentation
clone :: Functor f => ClonerFamily a a' b b' -> RefFamily f a a' b b'Source
Converts a universal lens instance back into a polymorphic lens.
Types
type ClonerFamily a a' b b' = RefFamily (Cloning b' b) a a' b b'Source
type Cloner a b = ClonerFamily a a b bSource