Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
642 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...