Lenses: composition back and (.) In the context of the lens

I read this article and in one of my sections it says:

The lenses fold back. Could we do (.)as functions?

You are right, we could. We are not for various reasons, but intuition is correct. Lenses should be combined with both functions. One important thing is that this id can be either up to compose with any lens without affecting it.

What does it mean that the lenses make up the back?

Also, what does this mean: can we do (.)as functions?

(.)is a function and, using it with Lens, does it (.)behave like something else?

+4
source share
2 answers

Getter , , view. , fst:

view _1 :: (a,b) -> a

:

view _1 . view _2 :: (c, (a,b)) -> a  -- First take the second pair element, then the first 
view (_1 . _2)    :: ((b,a) ,c) -> a   -- This is "backwards" (exactly the opposite order of the above)

(.) , . f . g " g, f", first use the lens f, then use the lens g. , (.) , .

+4

Lens type:

type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t

, Lens'. :

forall f. Functor f => (a -> f a) -> s -> f s

, (a -> f a) s, , (s -> f s). ( f , , . .) :

  • , , .
  • , - , .

( , , , "" "" .)

, . , (.) :

(.) :: (y -> z) -> (x -> y) -> (x -> z)

( forall). x a -> f a, y s -> f s z t -> f t. (.) :

((s -> f s) -> t -> f t) -> ((a -> f a) -> s -> f s) -> ((a -> f a) -> t -> f t)

, , (a -> f a) -> (t -> f t). , firstLens . secondLens , secondLens firstLens. , OO-, , .

+6

Source: https://habr.com/ru/post/1536656/


All Articles