Portability | ghc |
---|---|

Stability | beta |

Maintainer | Neil Sculthorpe <neil@ittc.ku.edu> |

Safe Haskell | Safe-Inferred |

This module defines the KURE `Lens`

type, along with some useful operations.

- data Lens c m a b
- lens :: Translate c m a ((c, b), b -> m a) -> Lens c m a b
- lensT :: Lens c m a b -> Translate c m a ((c, b), b -> m a)
- focusR :: Monad m => Lens c m a b -> Rewrite c m b -> Rewrite c m a
- focusT :: Monad m => Lens c m a b -> Translate c m b d -> Translate c m a d
- pureL :: Monad m => (a -> b) -> (b -> a) -> Lens c m a b
- failL :: Monad m => String -> Lens c m a b
- catchL :: MonadCatch m => Lens c m a b -> (String -> Lens c m a b) -> Lens c m a b
- testLensT :: MonadCatch m => Lens c m a b -> Translate c m a Bool
- bidirectionalL :: Monad m => BiTranslate c m a b -> Lens c m a b
- injectL :: (Monad m, Injection a g) => Lens c m a g
- projectL :: (Monad m, Injection a g) => Lens c m g a

# Lenses

A `Lens`

is a way to focus on a sub-structure of type `b`

from a structure of type `a`

.

lens :: Translate c m a ((c, b), b -> m a) -> Lens c m a bSource

The primitive way of building a `Lens`

.
If the unfocussing function is applied to the value focussed on then it should succeed,
and produce the same value as the original argument (of type `a`

).

pureL :: Monad m => (a -> b) -> (b -> a) -> Lens c m a bSource

Construct a `Lens`

from two pure functions.

catchL :: MonadCatch m => Lens c m a b -> (String -> Lens c m a b) -> Lens c m a bSource

A `Lens`

is deemed to have failed (and thus can be caught) if either it fails on the way down, or,
crucially, if it would fail on the way up for an unmodified value. However, actual failure on the way up is not caught
(as by then it is too late to use an alternative `Lens`

). This means that, in theory, a use of `catchL`

could cause a succeeding `Lens`

application to fail.
But provided `lens`

is used correctly, this should never happen.

testLensT :: MonadCatch m => Lens c m a b -> Translate c m a BoolSource

Check if the focusing succeeds, and additionally whether unfocussing from an unchanged value would succeed.

bidirectionalL :: Monad m => BiTranslate c m a b -> Lens c m a bSource

Construct a `Lens`

from a `BiTranslate`

.