How does "multi-argument" functional composition work (e.g. fmap . fmap)?

144 views Asked by At

When we have the expression:

(fmap . fmap) function nested_functor

I would expect it to translate to something like

fmap (fmap function nested_functor)

Though it surprisingly seems to behave as

fmap (fmap function) nested_functor

Why?

1

There are 1 answers

2
Daniel Wagner On BEST ANSWER

Well, just look at the definition of (.):

(f . g) x = f (g x)

So,

(fmap . fmap) function = fmap (fmap function)

Adding an additional argument at the end doesn't really change the equation -- just makes it more specific.

(fmap . fmap) function nested_functor = fmap (fmap function) nested_functor

(N.B. function application is left associative, so f x y means (f x) y.)