Harris Dong
Harris Dong

Reputation: 3

Puzzling function composition

How can I make sense of function composition in the following expression?

map . foldr (.) id :: [b -> b] -> [b] -> [b]

Upvotes: 0

Views: 100

Answers (1)

Luka Rahne
Luka Rahne

Reputation: 10447

f :: [a->a] -> a -> a
f = foldr (.) id

This takes list of functions and compose them together

for example

foldr (.) id [(+1),(+2)] == ((+1) . ((+2) . id)) == (+3)

Function application has higest fixity and map is made last

map . foldr (.) id == \x -> map ( foldr (.) id x )

It maps foldr (.) id over list (2nd argument) after first argument (list of functions) is applied

Upvotes: 9

Related Questions