lens-family-core-0.0.1: Haskell 98 Lens Families

Safe HaskellSafe-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 ClonerFamily a a' b b' (or Cloner a b). Then, inside a where clause, you use clone to create a LensFamily type.

For example.

 example :: ClonerFamily a a' b b' -> Example
 example l = ... x ^. cl ... cl ^= y ...
   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 Getters and Setters in the function. Otherwise you only need to use the monomorphic GetterFamily / Getter or SetterFamily / Setter.



clone :: Functor f => ClonerFamily a a' b b' -> LensFamily f a a' b b'Source

Converts a universal lens instance back into a polymorphic lens.


type LensFamily f a a' b b' = (b -> f b') -> a -> f a'Source

type ClonerFamily a a' b b' = LensFamily (Cloning b' b) a a' b b'Source

type Cloner a b = ClonerFamily a a b bSource