← Back

Functional Programming

Referential Transparency

An expression is called referentially transparent if it can be replaced with its corresponding value without changing the program's behavior.

Pure Function

A pure function is a function which, given the same input, always returns the same output, and has no side-effects.

Higher Order Functions

A higher order function is a function that takes a function as an argument, or returns a function.

Currying

Currying is converting a single function of n arguments into n functions with a single argument each. The advantage of currying functions is the ability to partially apply only some arguments.

f = (x,y,z) => x + y + z

when curried becomes,

f = x => y => z => x + y + z

Many functional languages let you write f x y z. If you only call f x y then you get a partially-applied functio

Partial Application

Partial function application refers to the process of fixing a number of arguments to a function, producing another function of smaller arity. Curried functions can be partially applied one argument at a time.

Tail Recursion

If the last thing a function does is call another function (or itself), a sim- ple jump takes place instead of a stack push. Consequently, a function that always calls itself will run forever, without causing a stack overflow or consuming additional memory.