How to write with id change type

If the type foldris

> :t foldr
forall a b. (a -> b -> b) -> b -> [a] -> b

and

> :t id
forall a. a -> a

then I would expect it foldr (.) idto be of the same type as foldr, and not

> :t foldr (.) id
forall b. [b -> b] -> b -> b

It seems like I'm mistaken in how the composition works, because I thought that for the function fthat f . idwould give f(id(x)) == f(x), preserving the type f. What I do not understand to clarify the meaning foldr (.) idand composition as a whole?

+4
source share
3 answers

id, foldr . id ( ). foldr, , , , Haskell.

, E, <23 > id foldr: < > 26 Haskell , . , , succ (.) id Enum ((c -> c) -> (a -> c) -> a -> c) => (a -> c) -> a -> c.

foldr, ,

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

(x->y) = (x->z) foldr, .. y = z,

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

 foldr (.) :: (x->y) -> [y->y] -> (x->y)

id x = y,

 foldr (.) id :: [x->x] -> (x->x)
+11

foldr id. foldr . id. foldr to (.), id.

+6

, , , ( ). id - , . , . [b -> b] -> (b -> b).

, Haskell , . , .

+1

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


All Articles