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?
I guess I can answer this from authority.
Is there a reason for using the books way that is much better than using all ($) symbols?
There's no special reason. Bryan and I both prefer to reduce line noise. .
is quieter than $
. As a result, the book uses the f . g . h $ x
syntax.