Question on evaluating function compostion

Hi, all I'm having trouble in understanding function evaluation in Haskell. I came across the following line, which is somewhat cryptic to me. (liftM . (+)) 1 [2] Could you explain how the expression evaluates? I thought that to evalutate two composed functions, I should apply right function to get a result and then apply left function with the result. e.g. f.g x y = f (g x y) = f z = result So I guessed that Haskell evaluated above expression as follows: (liftM . (+)) 1 [2] ---> ((liftM . (+)) 1) [2] ---> (A) (liftM (+1)) [2] --> [3] Why did Haskell, however, not try to fully evaluate addition, like following? (liftM . (+)) 1 [2] ---> liftM ((+) 1 [2]) ---> error Does (f . g) x y z equal ((((f . g) x) y) z) in haskell? Any guide will be appreciated. Chul-Woong

Does (f . g) x y z equal ((((f . g) x) y) z) in haskell?
Yes: (f . g) x y z = (((f (g (x)) (y)) (z)) = f (g x) y z since in Haskell as a higher-order functional language a bare function mentioned to the left is supposed to bind its argument stronger first before any lower-order arguments are allowed to start acting rightwards. (did-not (have (this-readability-problem)) lisp)

Why did Haskell, however, not try to fully evaluate addition, like following? (liftM . (+)) 1 [2] ---> liftM ((+) 1 [2]) ---> error
Haskell functions only consume one argument, not two. The composed function is applied to the first argument, which is 1. That returns a new function, which is applied to the next argument, which is [2]. e
participants (4)
-
Chul-Woong Yang
-
Erik Price
-
John Wiegley
-
Roman Czyborra