What is the difference between the dot (.) and the dollar sign ($)?
As I understand it, they are both syntactic sugar for not needing to use parentheses.
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
$operator is for avoiding parentheses. Anything appearing after it will take precedence over anything that comes before.For example, let’s say you’ve got a line that reads:
If you want to get rid of those parentheses, any of the following lines would also do the same thing:
The primary purpose of the
.operator is not to avoid parentheses, but to chain functions. It lets you tie the output of whatever appears on the right to the input of whatever appears on the left. This usually also results in fewer parentheses, but works differently.Going back to the same example:
(1 + 1)doesn’t have an input, and therefore cannot be used with the.operator.showcan take anIntand return aString.putStrLncan take aStringand return anIO ().You can chain
showtoputStrLnlike this:If that’s too many parentheses for your liking, get rid of them with the
$operator: