1
votes

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
All functions are single-argument, i.e. a->b->c is the same as a->(b->c). Build from here. - n. 1.8e9-where's-my-share m.
... and so f x y is the same as (f x) y. (f :: a->(b->c), x :: a, y :: b) - Will Ness

1 Answers

9
votes

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.)