Search code examples
functionhaskelllambda

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.


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].