[Haskell-beginners] Question on evaluating function compostion

Chul-Woong Yang cwyang at aranetworks.com
Wed Aug 20 09:59:13 UTC 2014


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140820/d0531972/attachment.html>


More information about the Beginners mailing list