What defines a functional programming language?
Tags: functional, programming, philosophy
Published: 2022-02-28 14:48:22

For future reference, here are two different takes I've come across. They should illustrate the difficulty of defining what a functional programming language is.

The [Ceylon FAQ](https://ceylon-lang.org/documentation/1.1/faq/language-design/#functional_programming) writes:

> What makes a programming language "functional"?
>
> I suppose I can try to take a bit of a guess at what you might mean, but that leaves me even more confused:
>
> - Does it mean that all functions are **pure** (without side effect) and there are no variables? Then Lisp and ML aren't functional? So the only well-known functional language is Haskell?
>
> - Does it mean **support for higher-order functions**? Then Smalltalk, Python, Ruby, JavaScript, C#, Java 8, Ceylon, and arguably even C are all functional programming languages?
>
> - Does it mean **no loops**? What if a programming language defines `for` as a syntax sugar for a function call? Oh, so then "functional programming language" boils down to **not having `break`, `continue` and `return`**?
>
> - Does it mean **support for parametric polymorphism**? Then C# and Java 5 are functional?
>
> - Could it mean an **emphasis upon higher-level abstractions** named after definitions in **category theory**? Then, again, Scheme and ML are excluded?

But this approach seems to be based on identifying a _single individual feature_ that makes a language into "a functional programming language". This is obviously flawed. It seems rather obvious that the definition of a functional programming language must be a _combination_ of features.

They conclude with such a combination:

> Perhaps what you really want to ask is:
>
> - Does [a certain language] encourage you to write code using **immutability**, **parametric polymorphism**, and **higher order functions**?

[Another take](https://youtu.be/QyJZzq0v7Z4?t=2547) goes by Richard Feldman, where he illustrates:

> How do you look at a programming language and decide this is a functional programming language or not? How do you do it?
>
> A: It's a functional programming language if it has **support for first-class functions**!
>
> B: Ok, so Java is a functional programming language?
>
> A: No, no, not Java. They have to be **pure**.
>
> B: Ok, so OCaml and Clojure are not a functional programming languages?
>
> A: No, no, those count. But ok, you need **immutability**, that's important.
>
> B: Ok, so Rust is a functional programming language? It's immutable by default, even.
>
> A: No, no, not like that...

Then he concludes:

> You know you just go around in circles. One person suggested a score, like if you have a certain number of things checked off,
> then like you cross a threshold and the language is considered functional.
>
> But ultimately I ended up concluding that classifying languages as functional or not is:
> - kind of arbitrary
> - definitely very fuzzy
>
> and ultimately not as important as talking about the _functional style_ and the language's support for the style of being **able to avoid mutation and side-effects**, and still have a really good experience.