Safe Haskell | None |
---|---|

Language | Haskell2010 |

## Synopsis

- type Lens s t a b = forall p. Strong p => Optic p s t a b
- type Lens' s a = Lens s s a a
- type Colens s t a b = forall p. Costrong p => Optic p s t a b
- type Colens' t b = Lens t t b b
- lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
- lensVl :: (forall f. Functor f => (a -> f b) -> s -> f t) -> Lens s t a b
- matching :: (s -> (c, a)) -> ((c, b) -> t) -> Lens s t a b
- cloneLens :: ALens s t a b -> Lens s t a b
- colens :: (b -> s -> a) -> (b -> t) -> Colens s t a b
- colensVl :: (forall f. Functor f => (t -> f s) -> b -> f a) -> Colens s t a b
- comatching :: ((c, s) -> a) -> (b -> (c, t)) -> Colens s t a b
- cloneColens :: AColens s t a b -> Colens s t a b
- type Grate s t a b = forall p. Closed p => Optic p s t a b
- type Grate' s a = Grate s s a a
- grate :: (((s -> a) -> b) -> t) -> Grate s t a b
- grateVl :: (forall f. Functor f => (f a -> b) -> f s -> t) -> Grate s t a b
- inverting :: (s -> a) -> (b -> t) -> Grate s t a b
- cloneGrate :: AGrate s t a b -> Grate s t a b
- united :: Lens' a ()
- voided :: Lens' Void a
- represented :: Representable f => Grate (f a) (f b) a b
- distributed :: Distributive f => Grate (f a) (f b) a b
- endomorphed :: Grate' (Endo a) a
- precomposed :: Grate (Lin a b1 c) (Lin a b2 c) (Vec a b1) (Vec a b2)
- dotted :: Grate c (Cov a c) a a
- continued :: Grate c (Cont a c) a a
- continuedT :: Grate c (ContT a m c) (m a) (m a)
- calledCC :: MonadCont m => Grate a (m a) (m b) (m a)
- zipsWith0 :: AGrate s t a b -> b -> t
- zipsWith2 :: AGrate s t a b -> (a -> a -> b) -> s -> s -> t
- zipsWith3 :: AGrate s t a b -> (a -> a -> a -> b) -> s -> s -> s -> t
- zipsWith4 :: AGrate s t a b -> (a -> a -> a -> a -> b) -> s -> s -> s -> s -> t
- zipsWithF :: Functor f => AGrate s t a b -> (f a -> b) -> f s -> t
- toPastro :: ALens s t a b -> p a b -> Pastro p s t
- toTambara :: Strong p => ALens s t a b -> p a b -> Tambara p s t
- toClosure :: Closed p => AGrate s t a b -> p a b -> Closure p s t
- toEnvironment :: Closed p => AGrate s t a b -> p a b -> Environment p s t
- class Profunctor p => Strong (p :: Type -> Type -> Type) where
- class Profunctor p => Costrong (p :: Type -> Type -> Type) where
- class Profunctor p => Closed (p :: Type -> Type -> Type) where
- closed :: p a b -> p (x -> a) (x -> b)

# Lens

type Lens s t a b = forall p. Strong p => Optic p s t a b Source #

\( \mathsf{Lens}\;S\;A = \exists C, S \cong C \times A \)

type Colens s t a b = forall p. Costrong p => Optic p s t a b Source #

\( \mathsf{Lens}\;S\;A = \exists C, S \times C \cong A \)

lensVl :: (forall f. Functor f => (a -> f b) -> s -> f t) -> Lens s t a b Source #

Transform a Van Laarhoven lens into a profunctor lens.

Compare `grateVl`

and `traversalVl`

.

*Caution*: In order for the generated optic to be well-defined,
you must ensure that the input satisfies the following properties:

abst Identity ≡ Identity

fmap (abst f) . (abst g) ≡ getCompose . abst (Compose . fmap f . g)

More generally, a profunctor optic must be monoidal as a natural transformation:

o id ≡ id

o (

`Procompose`

p q) ≡`Procompose`

(o p) (o q)

matching :: (s -> (c, a)) -> ((c, b) -> t) -> Lens s t a b Source #

Obtain a `Lens`

from its free tensor representation.

colens :: (b -> s -> a) -> (b -> t) -> Colens s t a b Source #

Obtain a `Colens`

from a getter and setter.

`colens`

f g ≡ \f g ->`re`

(`lens`

f g)`colens`

bsia bt ≡`colensVl`

`$`

\ts b -> bsia b`<$>`

(ts . bt`$`

b)`review`

$`colens`

f g ≡ f`set`

.`re`

$`re`

(`lens`

f g) ≡ g

*Caution*: Colenses are recursive, similar to ArrowLoop.
In addition to the normal optic laws, the input functions must have
the correct laziness annotations.

For example, this is a perfectly valid `Colens`

:

ct21 :: Colens a b (a, c) (b, c) ct21 = flip colens fst $ ~(_,c) b -> (b,c)

However removing the annotation will result in a faulty optic.

See `Property`

.

colensVl :: (forall f. Functor f => (t -> f s) -> b -> f a) -> Colens s t a b Source #

Transform a Van Laarhoven colens into a profunctor colens.

Compare `grateVl`

.

*Caution*: In addition to the normal optic laws, the input functions
must have the correct laziness annotations.

For example, this is a perfectly valid `Colens`

:

ct21 :: Colens a b (a, c) (b, c) ct21 = colensVl $ f ~(a,b) -> (,b) $ f a

However removing the annotation will result in a faulty optic.

comatching :: ((c, s) -> a) -> (b -> (c, t)) -> Colens s t a b Source #

Obtain a `Colens`

from its free tensor representation.

`>>>`

`fib = comatching (uncurry L.take . swap) (id &&& L.reverse) --fib :: Colens Int [Int] [Int] [Int]`

`>>>`

[89,55,34,21,13,8,5,3,2,1,1]`10 & fib ..~ \xs -> 1 : 1 : Prelude.zipWith (+) xs (Prelude.tail xs)`

cloneColens :: AColens s t a b -> Colens s t a b Source #

TODO: Document

# Grate

type Grate s t a b = forall p. Closed p => Optic p s t a b Source #

\( \mathsf{Grate}\;S\;A = \exists I, S \cong I \to A \)

grate :: (((s -> a) -> b) -> t) -> Grate s t a b Source #

Obtain a `Grate`

from a nested continuation.

The resulting optic is the corepresentable counterpart to `Lens`

,
and sits between `Iso`

and `Setter`

.

A `Grate`

lets you lift a profunctor through any representable
functor (aka Naperian container). In the special case where the
indexing type is finitary (e.g. `Bool`

) then the tabulated type is
isomorphic to a fied length vector (e.g. 'V2 a').

The identity container is representable, and representable functors are closed under composition.

See https://www.cs.ox.ac.uk/jeremy.gibbons/publications/proyo.pdf
section 4.6 for more background on `Grate`

s, and compare to the
*lens-family* version.

*Caution*: In order for the generated optic to be well-defined,
you must ensure that the input function satisfies the following
properties:

sabt ($ s) ≡ s

sabt (k -> f (k . sabt)) ≡ sabt (k -> f ($ k))

More generally, a profunctor optic must be monoidal as a natural transformation:

o id ≡ id

o (

`Procompose`

p q) ≡`Procompose`

(o p) (o q)

See `Property`

.

grateVl :: (forall f. Functor f => (f a -> b) -> f s -> t) -> Grate s t a b Source #

Transform a Van Laarhoven grate into a profunctor grate.

Compare `lensVl`

& `cotraversalVl`

.

*Caution*: In order for the generated family to be well-defined,
you must ensure that the traversal1 law holds for the input function:

abst runIdentity ≡ runIdentity

abst f . fmap (abst g) ≡ abst (f . fmap g . getCompose) . Compose

See `Property`

.

inverting :: (s -> a) -> (b -> t) -> Grate s t a b Source #

Construct a `Grate`

from a pair of inverses.

cloneGrate :: AGrate s t a b -> Grate s t a b Source #

TODO: Document

# Optics

There is a '()' in everything.

`>>>`

()`"hello" ^. united`

`>>>`

"hello"`"hello" & united .~ ()`

voided :: Lens' Void a Source #

There is everything in a `Void`

.

`>>>`

[]`[] & fmapped . voided <>~ "Void"`

`>>>`

Nothing`Nothing & fmapped . voided ..~ abs`

represented :: Representable f => Grate (f a) (f b) a b Source #

Obtain a `Grate`

from a `Representable`

functor.

distributed :: Distributive f => Grate (f a) (f b) a b Source #

Obtain a `Grate`

from a distributive functor.

endomorphed :: Grate' (Endo a) a Source #

Obtain a `Grate`

from an endomorphism.

`>>>`

14`flip appEndo 2 $ zipsWith2 endomorphed (+) (Endo (*3)) (Endo (*4))`

precomposed :: Grate (Lin a b1 c) (Lin a b2 c) (Vec a b1) (Vec a b2) Source #

Obtain a `Grate`

from a linear map.

continuedT :: Grate c (ContT a m c) (m a) (m a) Source #

# Operators

zipsWith0 :: AGrate s t a b -> b -> t Source #

Set all fields to the given value.

This is essentially a restricted variant of `review`

.

zipsWith3 :: AGrate s t a b -> (a -> a -> a -> b) -> s -> s -> s -> t Source #

Zip over a `Grate`

with 3 arguments.

zipsWith4 :: AGrate s t a b -> (a -> a -> a -> a -> b) -> s -> s -> s -> s -> t Source #

Zip over a `Grate`

with 4 arguments.

toEnvironment :: Closed p => AGrate s t a b -> p a b -> Environment p s t Source #

Use a `Grate`

to construct an `Environment`

.

# Classes

class Profunctor p => Strong (p :: Type -> Type -> Type) where #

Generalizing `Star`

of a strong `Functor`

*Note:* Every `Functor`

in Haskell is strong with respect to `(,)`

.

This describes profunctor strength with respect to the product structure of Hask.

## Instances

class Profunctor p => Costrong (p :: Type -> Type -> Type) where #

## Instances

MonadFix m => Costrong (Kleisli m) | |

Costrong p => Costrong (Yoneda p) | |

Costrong p => Costrong (Coyoneda p) | |

Costrong (Cotambara p) | |

Costrong (Copastro p) | |

Functor f => Costrong (Costar f) | |

ArrowLoop p => Costrong (WrappedArrow p) | |

Defined in Data.Profunctor.Strong unfirst :: WrappedArrow p (a, d) (b, d) -> WrappedArrow p a b # unsecond :: WrappedArrow p (d, a) (d, b) -> WrappedArrow p a b # | |

Costrong (Tagged :: Type -> Type -> Type) | |

Costrong (Conjoin j) Source # | |

Costrong ((->) :: Type -> Type -> Type) | |

Defined in Data.Profunctor.Strong | |

Functor f => Costrong (Cokleisli f) | |

Costrong (GrateRep a b) Source # | |

Strong p => Costrong (Re p s t) Source # | |

(Costrong p, Costrong q) => Costrong (Sum p q) | |

(Costrong p, Costrong q) => Costrong (Product p q) | |

(Functor f, Costrong p) => Costrong (Tannen f p) | |

class Profunctor p => Closed (p :: Type -> Type -> Type) where #

A strong profunctor allows the monoidal structure to pass through.

A closed profunctor allows the closed structure to pass through.