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

Explanation of lambda functions in Haskell

what is the x doing at the end? Why do I need to write it there?

(\x -> (>=5) x)

If I am calling the function like this: (\x -> (>=5) x) 5, what is the second x doing?
Maybe someone can explain this to me.

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

>Solution :

The (>= 5) is a section of an infix operator [Haskell-wiki], it is equivalent to \y -> y >= 5, it is thus a function, and we apply x to that function. This thus means that:

\x -> (>= 5) x

is thus equivalent to:

\x -> x >= 5

or simply:

(>= 5)

due to η-reduction [Haskell-wiki].

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