In Haskell, I often write expressions with $’s. I find it quite natural and readable, but I sometimes read it is bad form and do not understand why it should be.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The following are all good form:
I’ve put them in rough order of my preference, though as always taste varies, and context may demand a different choice. I’ve also occasionally seen
when each of the
bar,baz, andquuxsubexpressions are long. The following is bad form:There are two reasons this is less preferable. First, fewer subexpressions can be copied and pasted into an auxiliary definition during refactoring; with all
($)operators, only subexpressions that include thexargument are valid refactorings, whereas with(.)and($)operators even subexpressions likebar . bazorbaz . quuxcan be pulled out into a separate definition.The second reason to prefer
(.)is in anticipation of a possible change to the fixity of($); currently,($)isinfixr, meaning it associates to the right, like so:However,
($)would be useful in more expressions if it wereinfixl; for example, something like…which currently cannot be expressed without parentheses. The “bad form” example, when parsed with an
infixlapplication, would bewhich means something significantly different. So, future-proof your code by avoiding this form.