“Functional programming” has a clear meaning, but does “functional language”?

后端 未结 10 2051
悲哀的现实
悲哀的现实 2021-02-01 16:12

I understand very clearly the difference between functional and imperative programming techniques. But there\'s a widespread tendency to talk of \"functional languages\

10条回答
  •  走了就别回头了
    2021-02-01 16:41

    Among people who study programming languages for a living, "functional programming language" is a pretty weakly bound term. There is a strong consensus that:

    • Any language that calls itself functional must support first-class, nested functions with lexical scoping rules.

    A significant minority also reserve the term "functional language" for languages which are:

    • Pure (or side-effect-free, referentially transparent, see also)

    as in languages like Agda, Clean, Coq, and Haskell.

    Beyond that, what's considered a functional programming language is often a matter of intent, that is, whether is designers want it to be called "functional".

    Perl and Smalltalk are examples of languages that support first-class functions but whose designers don't call them functional. Objective Caml is an example of a language that is called functional even though it has a full object system with inheritance and everything.

    Languages that are called "functional" will tend to have features like the following (taken from Defining point of functional programming):

    • Anonymous functions (lambda expressions)
    • Recursion (more prominent as a result of purity)
    • Programming with expressions rather than statements (again, from purity)
    • Closures
    • Currying / partial application
    • Lazy evaluation
    • Algebraic data types and pattern matching
    • Parametric polymorphism (a.k.a. generics)

    The more a particular programming language has syntax and constructs tailored to making the various programming features listed above easy/painless to express & implement, the more likely someone will label it a "functional language".

提交回复
热议问题