Anonymous function #
We have seen in the dedicated section that a function can be written anonymously, as a lambda expression.
Anonymous functions are a traditional feature of functional languages (like Haskell). But they have also been integrated to a variety of imperative languages, for instance:
- Python (since 1994),
- Javascript (since its initial release in 1995),
- C# (since 2007)
- C++ (since 2011)
- Java (since 2014)
- Rust (since its initial release in 2015)
In Haskell #
Syntax. “$\lambda x.$” in Haskell is written
\x ->
Example. The two following functions are equivalent:
aFunction :: Integer -> Integer aFunction x = x + 2 theSameFunction :: Integer -> Integer theSameFunction = \x -> x + 2