“功能性编程”有明确的含义,但确实使用“功能性语言”? [英] "Functional programming" has a clear meaning, but does "functional language"?

查看:226
本文介绍了“功能性编程”有明确的含义,但确实使用“功能性语言”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常清楚地了解功能性和命令性编程技术之间的区别。但是有一种普遍倾向于讨论函数式语言的问题,这让我很困惑。

当然像Haskell这样的语言更热情到函数式编程,而不是像C这样的其他语言。但即使是前者也是I / O(它只是把它留在贫民窟中)。你可以用C编写功能程序(这很荒谬)。所以,也许这只是一个程度问题。

即使是程度问题,当有人称Scheme为功能语言时,这又意味着什么?我看到的大多数Scheme代码都是必不可少的。如果你想要的话,那么这个Scheme是否可以很容易地用功能性风格来写? Lua和Python也是如此。他们也是功能性语言吗?



我(真的)不想成为语言警察。如果这只是一种松散的说话方式,那很好。我只是想弄清楚它是否有一些确定的含义(即使它是一个问题的含义),我没有看到。

解决方案

在以编程语言为生的人中,函数式编程语言是一个相当弱的术语。有一个强烈的共识:


  • 任何自称功能的语言都必​​须支持 first-class ,使用词法作用域规则嵌套函数



重要的少数民族还保留语言功能语言一词,这些语言是:b
$ b



和Agda,Clean,Coq和Haskell等语言一样。

除此之外,什么被视为函数式编程语言通常是意图,也就是设计师是否希望它被称为功能。



Perl和Smalltalk是支持一流功能但其设计人员不称其为功能的语言的示例。目标Caml是一种称为功能的语言示例,即使它具有带继承和全部功能的完整对象系统。



称为功能的语言将倾向于具有以下功能(取自定义函数式编程):
$ b



特定的编程语言的语法和结构更加适合于使各种编程功能以上容易/无痛表达&实施,更有可能有人将其标记为功能语言。

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

Of course some languages like Haskell are more hospitable to functional programming than other languages like C. But even the former does I/O (it just keeps it in a ghetto). And you can write functional programs in C (it's just absurdly harder). So maybe it's just a matter of degree.

Still, even as a matter of degree, what does it mean when someone calls Scheme a "functional language"? Most Scheme code I see is imperative. Is it just that Scheme makes it easy to write in a functional style if you want to? So too do Lua and Python. Are they "functional languages" too?

I'm (really) not trying to be a language cop. If this is just a loose way of talking, that's fine. I'm just trying to figure out whether it does have some definite meaning (even if it's a matter-of-degree meaning) that I'm not seeing.

解决方案

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:

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".

这篇关于“功能性编程”有明确的含义,但确实使用“功能性语言”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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