Agda-2.5.2: A dependently typed functional programming language and proof assistant

Safe Haskell | Safe
Language | Haskell2010

Agda.Utils.Lens

Contents

- Type-preserving lenses.
- Elementary lens operations.
- State accessors and modifiers.
- Read-only state accessors and modifiers.

Description

A cut-down implementation of lenses, with names taken from Edward Kmett's lens package.

Synopsis

- type Lens' i o = forall f. Functor f => (i -> f i) -> o -> f o
- (^.) :: o -> Lens' i o -> i
- set :: Lens' i o -> i -> o -> o
- over :: Lens' i o -> (i -> i) -> o -> o
- use :: MonadState o m => Lens' i o -> m i
- (.=) :: MonadState o m => Lens' i o -> i -> m ()
- (%=) :: MonadState o m => Lens' i o -> (i -> i) -> m ()
- (%==) :: MonadState o m => Lens' i o -> (i -> m i) -> m ()
- (%%=) :: MonadState o m => Lens' i o -> (i -> m (i, r)) -> m r
- view :: MonadReader o m => Lens' i o -> m i
- locally :: MonadReader o m => Lens' i o -> (i -> i) -> m a -> m a
- key :: Ord k => k -> Lens' (Maybe v) (Map k v)
- (<&>) :: Functor m => m a -> (a -> b) -> m b

# Type-preserving lenses.

type Lens' i o = forall f. Functor f => (i -> f i) -> o -> f o #

Van Laarhoven style homogeneous lenses. Mnemoic: "Lens inner outer".

# Elementary lens operations.

(^.) :: o -> Lens' i o -> i infixl 8 #

Get inner part `i` of structure `o` as designated by `Lens' i o`.

set :: Lens' i o -> i -> o -> o #

Set inner part `i` of structure `o` as designated by `Lens' i o`.

over :: Lens' i o -> (i -> i) -> o -> o #

Modify inner part `i` of structure `o` using a function `i -> i`.

# State accessors and modifiers.

use :: MonadState o m => Lens' i o -> m i #

Read a part of the state.

(.=) :: MonadState o m => Lens' i o -> i -> m () infix 4 #

Write a part of the state.

(%=) :: MonadState o m => Lens' i o -> (i -> i) -> m () infix 4 #

Modify a part of the state.

(%==) :: MonadState o m => Lens' i o -> (i -> m i) -> m () infix 4 #

Modify a part of the state monadically.

(%%=) :: MonadState o m => Lens' i o -> (i -> m (i, r)) -> m r infix 4 #

Modify a part of the state monadically, and return some result.

# Read-only state accessors and modifiers.

view :: MonadReader o m => Lens' i o -> m i #

Ask for part of read-only state.

locally :: MonadReader o m => Lens' i o -> (i -> i) -> m a -> m a #

Modify a part of the state in a subcomputation.

key :: Ord k => k -> Lens' (Maybe v) (Map k v) #

(<&>) :: Functor m => m a -> (a -> b) -> m b infix 4 #

Infix version of `for`.