当一种语言符合功能语言的标准时? [英] When a language qualifies as a functional language?

查看:117
本文介绍了当一种语言符合功能语言的标准时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一种语言应该具备作为功能语言的特征的特征是什么?当我们可以说一种语言 XYZ 支持功能范式吗?

解决方案


一种语言应该被限定为一种功能性语言的特征是什么?当我们可以说一种语言XYZ支持功能范式?

这是两个不同的问题。我会说,支持功能范式意味着:您可以像使用其他类型一样使用函数(在局部变量中使用它们,参数,...)

  • 您可以定义匿名函数(aka lambda函数)inline

  • 匿名函数可以访问在其环境中声明的变量(这是已知的作为闭包)



  • 通过这个定义,几乎任何现代主流编程语言都支持功能范式(除了C)。 / p>

    要被归类为功能性语言,语言需要将功能范式作为其主要范式或唯一范式,包括不变性和专注于纯粹(副作用 - 免费)功能。除上述之外,这通常意味着:


    • 支持声明不同类型的不可变类型

    • 支持模式匹配

    • 函数体由表达式组成,而不是语句


    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?

    解决方案

    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

    这篇关于当一种语言符合功能语言的标准时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆