Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Haskell function composition operator and 'space operator' precedence

First of all, I am very new to Haskell and for the moment I am just trying to prepare for an exam.
I have this expression:
reverse . take 3 [1 .. 10] and what I get is an error. Is that because space operator has bigger precedence (10) than . operator (9) and the expression above is equivalent to reverse . (take 3 [1..10]) which is reverse . ([1, 2, 3]) which is a composition between reverse and a list which makes no sense, right? I am trying to make sure I got that right, I didn’t really find something similar on the internet.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You’re basically correct. Prefix function application (what you called the "space operator") binds more tightly than any infix operator does. And for completeness, the way to fix the error is to do (reverse . take 3) [1 .. 10] or reverse . take 3 $ [1 .. 10] instead.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading