on-internet
← Community

Confirming why function composition cannot be written this way in Haskell

Stack Overflow ·

Consider the function f f x y z = x * y + z It can be correctly rewritten as such f x = ((.) (+) . (*)) x but not as such f x = (.) (+) . (*x) The above gives errors when trying to run. As I understand it, this is wrong because supplying y will first give a constant x*y, which is then supplied to (.) (+). However (.) (+) was expecting a function, not a constant. By comparison, in the correct version, (.) (+) . (*) is first supplied x, giving (.) (+) (x*), which then when supplied with y gives (+) (x*y) as we wanted. Is this correct?

Comments

Sign in or sign up to comment and upvote.

No comments yet.