1

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?

Chris Martin
30.9k12 gold badges83 silver badges142 bronze badges
asked Dec 8, 2016 at 18:17
2
  • 5
    All functions are single-argument, i.e. a->b->c is the same as a->(b->c). Build from here. Commented Dec 8, 2016 at 18:33
  • 5
    ... and so f x y is the same as (f x) y. (f :: a->(b->c), x :: a, y :: b) Commented Dec 8, 2016 at 18:49

1 Answer 1

9

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

answered Dec 8, 2016 at 19:11
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! My confusion was due to thinking through this as if function application would be right associative, and the mess was due to that (->) associating to the right in the type signatures... I am now finding it funny that functional application in type declarations has a different associativity than in the expressions themselves.
@PedroMorteRolo It is sort of symmetrical that way. With it set like it is, you can have no parentheses in an application of fn to 'two' arguments as fn x y and no parentheses in the corresponding type signature for fn :: Int -> Int -> Bool (for example). If they associated in the same way (regardless of which way that is), one of those two things would need parens and the other wouldn't.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.