Haskell function composition (.) and function application ($) idioms: correct use.

Posted by Robert Massaioli on Stack Overflow See other posts from Stack Overflow or by Robert Massaioli
Published on 2010-06-13T00:57:49Z Indexed on 2010/06/13 2:42 UTC
Read the original article Hit count: 217

I have been reading Real World Haskell and I am nearing the end but a matter of style has been niggling at me to do with the (.) and ($) operators.

When you write a function that is a composition of other functions you write it like:

f = g . h

But when you apply something to the end of those functions I write it like this:

k = a $ b $ c $ value

But the book would write it like this:

k = a . b . c $ value

Now to me they look functionally equivalent, they do the exact same thing in my eyes. However, the more I look, the more I see people writing their functions in the manner that the book does: compose with (.) first and then only at the end use ($) to append a value to evaluate the lot (nobody does it with many dollar compositions). Is there a reason for using the books way that is much better than using all ($) symbols? Or is there some best practice here that I am not getting? Or is it superfluous and I shouldn't be worrying about it at all? Thanks.

© Stack Overflow or respective owner

Related posts about best-practices

Related posts about haskell