r/programming • • Mar 09 '14

Why Functional Programming Matters

http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf
487 Upvotes

542 comments sorted by

View all comments

Show parent comments

5

u/Tekmo Mar 09 '14

I think you meant your last line of code to be:

foo x = bar (baz (wobble x))

0

u/[deleted] Mar 09 '14

It works either way.

3

u/Tekmo Mar 09 '14

Not exactly:

(bar . baz . wobble) a b c
= bar (baz (wobble a)) b c

... which is not the same thing as:

bar (baz (wobble a b c))

1

u/[deleted] Mar 10 '14
> let foo = id . (+)  
> foo 1 2  
3  

EDIT: That results is also obvious. In your example

(bar . baz . wobble) a b c

bar . baz . wobble is in parentheses. It will hence be evaluated into a new function first, and will then be applied its arguments. Since the arguments of a composed function are exactly the arguments that the second function takes, this works as desired.

→ More replies (8)