when you split a list using x:xs syntax why is it wrapped in a parentheses? what is the significance of the parentheses? why not [x:xs] or just x:xs?
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 cons cell doesn’t have to be parenthesized in every context, but in most contexts it is because
Function application binds tighter than any infix operator.
Burn this into your brain in letters of fire.
Example:
If parentheses were omitted the compiler would think you had an argument
xfollowed by an ill-placed infix operator, and it would complain bitterly. On the other hand this is OKIn this case neither
xnorxscan possibly be construed as part of a function application so no parentheses are needed.Note that the same wonderful rule function application binds tighter than any infix operator is what allows us to write
length xsin1 + length xswithout any parentheses. The infix rule giveth and the infix rule taketh away.