Safe Haskell | Safe-Inferred |
---|
- data MLens m a b = MLens (a -> m (b, b -> m a))
- type Lens a b = MLens Identity a b
- fromLens :: Monad m => Lens a b -> MLens m a b
- toLens :: (forall m. Monad m => MLens m a b) -> Lens a b
- lens :: Monad m => (a -> b) -> (b -> a -> a) -> MLens m a b
- getL :: Monad m => MLens m a b -> a -> m b
- setL :: Monad m => MLens m a b -> b -> a -> m a
- modL :: Monad m => MLens m b a -> (a -> a) -> b -> m b
- mapMLens :: (Monad m, Monad n) => Morph m n -> MLens m a b -> MLens n a b
- joinML :: Monad m => (a -> m (MLens m a b)) -> MLens m a b
- joinLens :: Monad m => MLens m a (MLens m a b) -> MLens m a b
- unitLens :: Monad m => MLens m a ()
- fstLens :: Monad m => MLens m (a, b) a
- sndLens :: Monad m => MLens m (a, b) b
- maybeLens :: Monad m => MLens m (Bool, a) (Maybe a)
- listLens :: Monad m => MLens m (Bool, (a, [a])) [a]
- ithLens :: Monad m => Int -> MLens m [a] a
- forkLens :: (Monoid a, Monad m) => MLens m a (a, a)
- justLens :: Monad m => a -> MLens m (Maybe a) a
- showLens :: (Monad m, Show a, Read a) => MLens m a String
- type Morph m n = forall a. m a -> n a
Monadic lenses data type
Monadic lenses.
The following representations would be also good for (MLens m a b)
:
a -> m (Store b (m a))
forall f . Functor f => (b -> m (f (m b))) -> a -> m (f (m a))
(a -> m b, b -> a -> m a)
The last representation has no efficient composition operation (the set operation on composition of n lenses use O(n * n) get operations with the last representation).
Using lenses which do not fulfil the lens laws are safe, but one should take extra care when doing program transformations or reasoning about code with impure lenses.
The following law is a minimum, but some lenses (which do logging) do not fulfil this:
-
getL
has no side effect, i.e.(getL k a >> return ())
can be replaced by(return ())
TODO: List laws, document which laws hold for each lenses.
MLens (a -> m (b, b -> m a)) |
Side-effect free lenses
type Lens a b = MLens Identity a bSource
Side-effect free lenses.
The following representations would be also good for (Lens a b)
:
forall m . Monad m => MLens m a b
Lens construction
Lens operations
Lens transformations
joinLens :: Monad m => MLens m a (MLens m a b) -> MLens m a bSource
It would be possible to define a Monad
instance for (MLens m a)
too, but monad laws would not hold.