Considering Haskell has currying functions, we can do this:
foo a b = a + b -- equivalent to `foo a = \\b -> a + b`
foo 1 -- ok, returns `\\b -> 1 + b`
fo
bar . foo 1 2
is bar . (foo 1 2)
not (bar . foo 1) 2
There's nothing mysterious going on here related to lambdas. Say we expanded the application of foo
to 1:
bar . foo 1 2
bar . (\b -> 1 + b) 2
Now, we apply the lambda to the 2
bar . 3
And there is your problem.
Conversely, if we place the parentheses correctly, we evaluate it like this:
(bar . foo 1) 2
(bar . (\b -> 1 + b)) 2
(\x -> bar ((\b -> 1 + b) x)) 2
bar 3