Data.Label.Total

fclabels-2.0.3: First class accessor labels implemented as lenses.

Safe Haskell | Safe
Language | Haskell98

Data.Label.Total

Contents

- Working in contexts.

Description

Default lenses for simple total getters and total possibly polymorphic, updates. Useful for creating accessor labels for single constructor datatypes. Also useful field labels that are shared between all the constructors of a multi constructor datatypes.

Synopsis

- type (:->) f o = Lens Total f o
- type Total = (->)
- lens :: (f -> o) -> ((o -> i) -> f -> g) -> (f -> g) :-> (o -> i)
- get :: ((f -> g) :-> (o -> i)) -> f -> o
- modify :: ((f -> g) :-> (o -> i)) -> (o -> i) -> f -> g
- set :: ((f -> g) :-> (o -> i)) -> i -> f -> g
- traverse :: Functor m => ((f -> g) :-> (o -> i)) -> (o -> m i) -> f -> m g
- lifted :: Monad m => ((f -> g) :-> (m o -> m i)) -> ((o -> i) :-> (m a -> m b)) -> (f -> g) :-> (m a -> m b)

# Documentation

type (:->) f o = Lens Total f o #

Total lens type specialized for total accessor functions.

type Total = (->) #

Context that represents computations that always produce an output.

lens #

Arguments

:: (f -> o) | Getter.
-> ((o -> i) -> f -> g) | Modifier.
-> (f -> g) :-> (o -> i) |

Create a total lens from a getter and a modifier.

We expect the following law to hold:

    get l (set l a f) == a

    set l (get l f) f == f

get :: ((f -> g) :-> (o -> i)) -> f -> o #

Get the getter function from a lens.

modify :: ((f -> g) :-> (o -> i)) -> (o -> i) -> f -> g #

Get the modifier function from a lens.

set :: ((f -> g) :-> (o -> i)) -> i -> f -> g #

Get the setter function from a lens.

# Working in contexts.

traverse :: Functor m => ((f -> g) :-> (o -> i)) -> (o -> m i) -> f -> m g #

Modify in some context.

lifted :: Monad m => ((f -> g) :-> (m o -> m i)) -> ((o -> i) :-> (m a -> m b)) -> (f -> g) :-> (m a -> m b) #

Lifted lens composition.

For example, useful when specialized to lists:

    :: (f :-> [o])
    -> (o :-> [a])
    -> (f :-> [a])