03 Lambdas

Now let's look closer at the syntax of anonymous functions:

Syntax

fun x1 ... xn -> e

Evaluation

A common mistake that people make is that people think the body of the function is evaluated when it's declared.


Anonymous functions are also known as lambda expressions. This comes from math, with λx.e being the notation. The λ means that "what follows is an anonymous function," like the fun keyword in OCaml.

Lambdas are popular in many languages

Lambda Style


Functions as values is a design decision in OCaml. We can use functions anywhere we use values. Functions can take functions as parameters, and functions can return functions. This is one of the main principles of functional programming.