When a language qualifies as a functional language

2019-07-23 05:24发布

问题:

What are the traits a language should have to be qualified as a functional language? When we can say that a language XYZ supports functional paradigm?

回答1:

What are the traits a language should have to be qualified as a functional language? When we can say that a language XYZ supports functional paradigm?

Those are two different question. I'd say that "supporting functional paradigm" means:

  • you can work with functions like with other types (use them in local variables, parameters, …)
  • you can define anonymous functions (a.k.a. lambda functions) inline
  • anonymous functions can access variables declared in their environment (this is known as closure)

By this definition, pretty much any modern mainstream programming language supports the functional paradigm (with the exception of C).

To be classified as "functional language", a language needs to focus on the functional paradigm as its primary or only paradigm, including immutability and focus on pure (side-effect-free) functions. Apart from the above, this usually means:

  • support for declaring immutable types like discriminated unions
  • support for pattern matching
  • function bodies are composed of expressions, not statements