什么语言实现函数式编程的功能?

时间:2020-12-05 11:34:21

Lisp developed a set of interesting language features quite early on in the academic world, but most of them never caught on in production environments.

Lisp在学术界很早就开发了一套有趣的语言功能,但大多数都没有在生产环境中流行。

Some languages, like JavaScript, adapted basic features like garbage collection and lexical closures, but all the stuff that might actually change how you write programs on a large scale, like powerful macros, the code-as-data thing and custom control structures, only seems to propagate within other functional languages, none of which are practical to use for non-trivial projects.

有些语言,比如JavaScript,改编了基本功能,如垃圾收集和词法闭包,但所有可能实际上改变你大规模编写程序的东西,如强大的宏,代码作为数据的东西和自定义控件结构,只有似乎在其他功能语言中传播,其中任何一种都不适用于非平凡的项目。

The functional programming community also came up with a lot of other interesting ideas (apart from functional programming itself), like referential transparency, generalised case-expressions (ie, pattern-matching, not crippled like C/C# switches) and curried functions, which seem obviously useful in regular programming and should be easy to integrate with existing programming practice, but for some reason seem to be stuck in the academic world forever.

函数式编程社区还提出了许多其他有趣的想法(除了函数式编程本身),如引用透明性,通用案例表达式(即模式匹配,不像C / C#开关那样残缺)和curried函数,似乎在常规编程中显然很有用,并且应该很容易与现有的编程实践集成,但由于某种原因似乎永远陷入了学术界。

Why do these features have such a hard time getting adopted? Are there any modern, practical languages that actually learn from Lisp instead of half-assedly copying "first class functions", or is there an inherent conflict that makes this impossible?

为什么这些功能很难被采用?是否有任何现代的,实用的语言实际上是从Lisp中学习而不是半复杂地复制“一流的功能”,还是存在使这不可能的内在冲突?

16 个解决方案

#1


20  

Are there any modern, practical languages that actually learn from Lisp instead of half-assedly copying "first class functions", or is there an inherent conflict that makes this impossible?

是否有任何现代的,实用的语言实际上是从Lisp中学习而不是半复杂地复制“一流的功能”,还是存在使这不可能的内在冲突?

Why aren't lisp, haskell, ocaml, or f# modern?

为什么不是lisp,haskell,ocaml或f#modern?

You might just need to take it on yourself and look at them and realize that they are more robust, with libraries like java, then you'd think.

您可能只需要自己接受并查看它们并意识到它们更强大,使用像Java这样的库,然后您就会想到。

A lot of features have been adopted from functional languages to other languages. But vice versa -- (some) functional languages have objects, for example.

从功能语言到其他语言已经采用了许多功能。但反之亦然 - (某些)功能语言具有对象。

#2


8  

I suggest you try Clojure. Syntactically beautiful dialect, functional (in the ML sense), and fast. You get immutability, software transactional memory, multiversion concurrency control, a REPL, SLIME support, and an inexhaustible FFI. It's the Lisp (& Haskell) for the Business Programmer. I'm having a great time using it daily in my real job.

我建议你试试Clojure。语法上美丽的方言,功能(在ML意义上),和快速。您将获得不变性,软件事务内存,多版本并发控制,REPL,SLIME支持以及取之不尽的FFI。它是商业程序员的Lisp(&Haskell)。我每天都在工作中度过愉快的时光。

#3


8  

There is no known correlation between a language "catching on" and whether or not is has powerful, well researched, well designed features.

语言“追赶”与是否具有强大,精心研究和精心设计的特征之间没有已知的相关性。

A lot has been said on the subject. It exists all over the place in technology, and also the arts. We know artist A has more training and produces works of greater breadth and depth than artist B, yet artist B is far more successful in the marketplace. Is it because there's a zeitgeist? Is is because artist B has better marketing? Is it because most people won't take the time to understand artist A? Maybe artist B is secretly awful and we should mistrust experts who make judgements about artists? Probably all of the above, to some degree or another.

关于这个问题已经说了很多。它遍布技术和艺术。我们知道艺术家A比艺术家B有更多的训练和制作更广泛和深度的作品,但艺术家B在市场上更为成功。是因为有一个时代精神?是因为艺术家B有更好的营销?是因为大多数人不会花时间去理解艺术家A吗?也许艺术家B暗中可怕,我们应该不信任对艺术家做出判断的专家?可能以上所有,在某种程度上。

This drives people who study the arts, and people who study programming languages, crazy.

这使得学习艺术的人和学习编程语言的人疯狂。

#4


8  

Scala is a cool functional/OO language with pattern matching, first class functions, and the like. It has the advantage of compiling to Java bytecode and inter-operates well with Java code.

Scala是一种很酷的功能/ OO语言,具有模式匹配,一流功能等。它具有编译为Java字节码并与Java代码良好互操作的优点。

#5


7  

Common Lisp, used in the real-world albeit not wildely so, I guess.

Common Lisp,在现实世界中使用,虽然不是很好,但我想。

#6


6  

Python or Ruby. See Paul Graham's thoughts on this in the question "I like Lisp but my company won't let me use it. What should I do?".

Python或Ruby。在“我喜欢Lisp,但我的公司不会让我使用它。我应该怎么做?”这个问题上看保罗格雷厄姆对此的看法。

#7


5  

Scala is the absolute king of languages which have adopted significant academic features. Higher kinds, self types, polymorphic pattern matching, etc. All of these are bleeding-edge (or near to it) academic research topics that have been incorporated into Scala as fundamental features. Arguably, this has been to the detriment of the langauge's simplicity, but it does lead to some very interesting patterns.

Scala是语言的绝对王者,它具有重要的学术特征。更高的种类,自我类型,多态模式匹配等等。所有这些都是前沿(或接近它)的学术研究课题,已被纳入Scala作为基本特征。可以说,这已经损害了语言的简洁性,但它确实导致了一些非常有趣的模式。

C# is more mainstream than Scala, but it also has adopted fewer of these "out-there" functional features. LINQ is a limited implementation for Wadler's generalized list comprehensions, and everyone knows about lambdas. But for all that, C# (rightfully) remains a bit conservative in adopting research features from the academic world.

C#比Scala更主流,但它也采用了更少的“外部”功能。 LINQ是Wadler广义列表推导的有限实现,每个人都知道lambdas。但就此而言,C#(理所当然地)在采用学术界的研究特色方面仍然有点保守。

#8


5  

Erlang has recently gained renewed exposure not only through being used by Twitter, but also by the rise of XMPP driven messaging and implementations such as ejabberd. It sports many of the ideas coming from functional programming being a language designed with that in mind. Initially used to run Telephone switches and conceived by Ericson to run the first GSM networks. It is still around, it is fully functional (as a language) and used in many production environments.

Erlang最近不仅通过Twitter使用,而且通过XMPP驱动的消息传递和ejabberd等实现的兴起获得了新的曝光。它体现了许多来自功能性编程的想法,这些想法是为此而设计的语言。最初用于运行电话交换机,由Ericson构思运行第一个GSM网络。它仍然存在,它功能齐全(作为一种语言)并在许多生产环境中使用。

#9


3  

Lua.

It's used as a scripting/extension language for a number of games (like World of Worcraft), and applications (Snort, NMAP, Wireshark, etc). In fact, according to an Adobe developer, Adobe's Lightroom is over 40% Lua.

它被用作许多游戏(如World of Worcraft)和应用程序(Snort,NMAP,Wireshark等)的脚本/扩展语言。事实上,根据Adobe开发人员的说法,Adobe的Lightroom超过40%的Lua。

The guys behind Lua have repeatedly listed Scheme and Lisp as major influences on Lua, and Lua has even been described as Scheme without the parentheses.

Lua背后的人反复将Scheme和Lisp列为对Lua的主要影响,而Lua甚至被描述为没有括号的Scheme。

#10


2  

Have you checked out F#

你看过F#吗?

#11


2  

Lot's of dynamic programming languages implement ideas from functional programming. The newer .Net languages (C# and VB) have what they call lambda's but these aren't side effect free.

很多动态编程语言都实现了函数式编程的思想。较新的.Net语言(C#和VB)具有他们所谓的lambda,但这些不是副作用。

It's not difficult combining concepts from functional programming and object oriented programming for example but it doesn't always make a lot of sense. Object oriented languages (try to) encapsulate state inside objects while functional languages encapsulate state inside functions. If you combine objects and functions in one language it gets harder to make sense of all this.

例如,将功能编程和面向对象编程的概念结合起来并不困难,但它并不总是很有意义。面向对象语言(尝试)将状态封装在对象内,而函数语言将状态封装在函数内。如果将对象和函数组合在一种语言中,则很难理解所有这些。

There have been a lot of languages that have combined these paradigms by just throwing them together (F#) and this can be usefull but I think we still need a couple of decades of playing with languages like this untill we can create a new paradigm that succesfully will combine the ideas from oo and functional programming.

已经有很多语言将这些范例组合在一起(F#)并且这可能是有用的但我认为我们仍然需要几十年的时间来玩这样的语言,直到我们可以创造一个成功的新范例将结合oo和函数式编程的思想。

#12


2  

C# 3.0 definitely does.

C#3.0绝对可以。

C# now has

C#现在有了

  1. Lambda Expressions
  2. Higher Order Functions
  3. 高阶函数

  4. Map / Reduce + Filter ( Folding?) to lists and all types which implement IEnumerable.
  5. Map / Reduce + Filter(Folding?)到列表以及实现IEnumerable的所有类型。

  6. LINQ
  7. Object + Collection Initializers.
  8. 对象+集合初始化器。

The last two list items may not fall under proper functional programming, anyways the answer is C# has implemented many useful concepts from Lisp etc.

最后两个列表项可能不属于正确的函数式编程,无论如何答案是C#已经实现了Lisp等许多有用的概念。

#13


2  

In addition to what was said, a lot of LISP goodness is based on guaranteed lack of side-effects and using built-in data structures. Both rarely hold in real world. ML is probably better functional base.

除了所说的之外,许多LISP的优点是基于保证缺乏副作用和使用内置数据结构。两者都很少在现实世界中存在。 ML可能是更好的功能基础。

#14


2  

Lisp developed a set of interesting language features quite early on in the academic world, but most of them never caught on in production environments.

Lisp在学术界很早就开发了一套有趣的语言功能,但大多数都没有在生产环境中流行。

Because the kind of people who manage software developers aren't the kinds of people who you can have an interesting chat comparing different language features with. Around 2000, I wanted to use LISP to implement XML-to-HTML transforms on our corporate website (this is around the time of Amazon implementing their backend in LISP). I didn't get to. This is mildly ironic seeing as the company I was working for made and sold a Common LISP environment.

因为那些管理软件开发人员的人并不是那种可以通过比较不同语言特征进行有趣聊天的人。大约2000年,我想使用LISP在我们的公司网站上实现XML到HTML的转换(这是亚马逊在LISP中实现其后端的时候)。我没有去。这是一个有点讽刺意味的事实,因为我正在为我们工作的公司制造并销售一个Common LISP环境。

#15


1  

Another "real-world" language that implements functional programming features is Javascript. Since absolutely everything has a value, then high-order functions are easily implemented. You also have other tenants of functional programming such as lambda functions, closures, and currying.

另一种实现函数式编程功能的“真实世界”语言是Javascript。由于绝对一切都有价值,因此很容易实现高阶函数。您还有其他功能编程租户,例如lambda函数,闭包和currying。

#16


0  

The features you refer to ("powerful" macros, the code-as-data thing and custom control structures) have not propagated within other functional languages. They died after Lisp taught us that they are a bad idea.

您引用的功能(“强大的”宏,代码作为数据的东西和自定义控件结构)没有在其他函数语言中传播。 Lisp告诉我们他们是个坏主意后,他们死了。

Modern functional languages (OCaml, Haskell, Erlang, Scala, F#, C# 3.0, JavaScript) do not have those features.

现代函数式语言(OCaml,Haskell,Erlang,Scala,F#,C#3.0,JavaScript)没有这些功能。

Cheers, Jon Harrop.

干杯,Jon Harrop。

#1


20  

Are there any modern, practical languages that actually learn from Lisp instead of half-assedly copying "first class functions", or is there an inherent conflict that makes this impossible?

是否有任何现代的,实用的语言实际上是从Lisp中学习而不是半复杂地复制“一流的功能”,还是存在使这不可能的内在冲突?

Why aren't lisp, haskell, ocaml, or f# modern?

为什么不是lisp,haskell,ocaml或f#modern?

You might just need to take it on yourself and look at them and realize that they are more robust, with libraries like java, then you'd think.

您可能只需要自己接受并查看它们并意识到它们更强大,使用像Java这样的库,然后您就会想到。

A lot of features have been adopted from functional languages to other languages. But vice versa -- (some) functional languages have objects, for example.

从功能语言到其他语言已经采用了许多功能。但反之亦然 - (某些)功能语言具有对象。

#2


8  

I suggest you try Clojure. Syntactically beautiful dialect, functional (in the ML sense), and fast. You get immutability, software transactional memory, multiversion concurrency control, a REPL, SLIME support, and an inexhaustible FFI. It's the Lisp (& Haskell) for the Business Programmer. I'm having a great time using it daily in my real job.

我建议你试试Clojure。语法上美丽的方言,功能(在ML意义上),和快速。您将获得不变性,软件事务内存,多版本并发控制,REPL,SLIME支持以及取之不尽的FFI。它是商业程序员的Lisp(&Haskell)。我每天都在工作中度过愉快的时光。

#3


8  

There is no known correlation between a language "catching on" and whether or not is has powerful, well researched, well designed features.

语言“追赶”与是否具有强大,精心研究和精心设计的特征之间没有已知的相关性。

A lot has been said on the subject. It exists all over the place in technology, and also the arts. We know artist A has more training and produces works of greater breadth and depth than artist B, yet artist B is far more successful in the marketplace. Is it because there's a zeitgeist? Is is because artist B has better marketing? Is it because most people won't take the time to understand artist A? Maybe artist B is secretly awful and we should mistrust experts who make judgements about artists? Probably all of the above, to some degree or another.

关于这个问题已经说了很多。它遍布技术和艺术。我们知道艺术家A比艺术家B有更多的训练和制作更广泛和深度的作品,但艺术家B在市场上更为成功。是因为有一个时代精神?是因为艺术家B有更好的营销?是因为大多数人不会花时间去理解艺术家A吗?也许艺术家B暗中可怕,我们应该不信任对艺术家做出判断的专家?可能以上所有,在某种程度上。

This drives people who study the arts, and people who study programming languages, crazy.

这使得学习艺术的人和学习编程语言的人疯狂。

#4


8  

Scala is a cool functional/OO language with pattern matching, first class functions, and the like. It has the advantage of compiling to Java bytecode and inter-operates well with Java code.

Scala是一种很酷的功能/ OO语言,具有模式匹配,一流功能等。它具有编译为Java字节码并与Java代码良好互操作的优点。

#5


7  

Common Lisp, used in the real-world albeit not wildely so, I guess.

Common Lisp,在现实世界中使用,虽然不是很好,但我想。

#6


6  

Python or Ruby. See Paul Graham's thoughts on this in the question "I like Lisp but my company won't let me use it. What should I do?".

Python或Ruby。在“我喜欢Lisp,但我的公司不会让我使用它。我应该怎么做?”这个问题上看保罗格雷厄姆对此的看法。

#7


5  

Scala is the absolute king of languages which have adopted significant academic features. Higher kinds, self types, polymorphic pattern matching, etc. All of these are bleeding-edge (or near to it) academic research topics that have been incorporated into Scala as fundamental features. Arguably, this has been to the detriment of the langauge's simplicity, but it does lead to some very interesting patterns.

Scala是语言的绝对王者,它具有重要的学术特征。更高的种类,自我类型,多态模式匹配等等。所有这些都是前沿(或接近它)的学术研究课题,已被纳入Scala作为基本特征。可以说,这已经损害了语言的简洁性,但它确实导致了一些非常有趣的模式。

C# is more mainstream than Scala, but it also has adopted fewer of these "out-there" functional features. LINQ is a limited implementation for Wadler's generalized list comprehensions, and everyone knows about lambdas. But for all that, C# (rightfully) remains a bit conservative in adopting research features from the academic world.

C#比Scala更主流,但它也采用了更少的“外部”功能。 LINQ是Wadler广义列表推导的有限实现,每个人都知道lambdas。但就此而言,C#(理所当然地)在采用学术界的研究特色方面仍然有点保守。

#8


5  

Erlang has recently gained renewed exposure not only through being used by Twitter, but also by the rise of XMPP driven messaging and implementations such as ejabberd. It sports many of the ideas coming from functional programming being a language designed with that in mind. Initially used to run Telephone switches and conceived by Ericson to run the first GSM networks. It is still around, it is fully functional (as a language) and used in many production environments.

Erlang最近不仅通过Twitter使用,而且通过XMPP驱动的消息传递和ejabberd等实现的兴起获得了新的曝光。它体现了许多来自功能性编程的想法,这些想法是为此而设计的语言。最初用于运行电话交换机,由Ericson构思运行第一个GSM网络。它仍然存在,它功能齐全(作为一种语言)并在许多生产环境中使用。

#9


3  

Lua.

It's used as a scripting/extension language for a number of games (like World of Worcraft), and applications (Snort, NMAP, Wireshark, etc). In fact, according to an Adobe developer, Adobe's Lightroom is over 40% Lua.

它被用作许多游戏(如World of Worcraft)和应用程序(Snort,NMAP,Wireshark等)的脚本/扩展语言。事实上,根据Adobe开发人员的说法,Adobe的Lightroom超过40%的Lua。

The guys behind Lua have repeatedly listed Scheme and Lisp as major influences on Lua, and Lua has even been described as Scheme without the parentheses.

Lua背后的人反复将Scheme和Lisp列为对Lua的主要影响,而Lua甚至被描述为没有括号的Scheme。

#10


2  

Have you checked out F#

你看过F#吗?

#11


2  

Lot's of dynamic programming languages implement ideas from functional programming. The newer .Net languages (C# and VB) have what they call lambda's but these aren't side effect free.

很多动态编程语言都实现了函数式编程的思想。较新的.Net语言(C#和VB)具有他们所谓的lambda,但这些不是副作用。

It's not difficult combining concepts from functional programming and object oriented programming for example but it doesn't always make a lot of sense. Object oriented languages (try to) encapsulate state inside objects while functional languages encapsulate state inside functions. If you combine objects and functions in one language it gets harder to make sense of all this.

例如,将功能编程和面向对象编程的概念结合起来并不困难,但它并不总是很有意义。面向对象语言(尝试)将状态封装在对象内,而函数语言将状态封装在函数内。如果将对象和函数组合在一种语言中,则很难理解所有这些。

There have been a lot of languages that have combined these paradigms by just throwing them together (F#) and this can be usefull but I think we still need a couple of decades of playing with languages like this untill we can create a new paradigm that succesfully will combine the ideas from oo and functional programming.

已经有很多语言将这些范例组合在一起(F#)并且这可能是有用的但我认为我们仍然需要几十年的时间来玩这样的语言,直到我们可以创造一个成功的新范例将结合oo和函数式编程的思想。

#12


2  

C# 3.0 definitely does.

C#3.0绝对可以。

C# now has

C#现在有了

  1. Lambda Expressions
  2. Higher Order Functions
  3. 高阶函数

  4. Map / Reduce + Filter ( Folding?) to lists and all types which implement IEnumerable.
  5. Map / Reduce + Filter(Folding?)到列表以及实现IEnumerable的所有类型。

  6. LINQ
  7. Object + Collection Initializers.
  8. 对象+集合初始化器。

The last two list items may not fall under proper functional programming, anyways the answer is C# has implemented many useful concepts from Lisp etc.

最后两个列表项可能不属于正确的函数式编程,无论如何答案是C#已经实现了Lisp等许多有用的概念。

#13


2  

In addition to what was said, a lot of LISP goodness is based on guaranteed lack of side-effects and using built-in data structures. Both rarely hold in real world. ML is probably better functional base.

除了所说的之外,许多LISP的优点是基于保证缺乏副作用和使用内置数据结构。两者都很少在现实世界中存在。 ML可能是更好的功能基础。

#14


2  

Lisp developed a set of interesting language features quite early on in the academic world, but most of them never caught on in production environments.

Lisp在学术界很早就开发了一套有趣的语言功能,但大多数都没有在生产环境中流行。

Because the kind of people who manage software developers aren't the kinds of people who you can have an interesting chat comparing different language features with. Around 2000, I wanted to use LISP to implement XML-to-HTML transforms on our corporate website (this is around the time of Amazon implementing their backend in LISP). I didn't get to. This is mildly ironic seeing as the company I was working for made and sold a Common LISP environment.

因为那些管理软件开发人员的人并不是那种可以通过比较不同语言特征进行有趣聊天的人。大约2000年,我想使用LISP在我们的公司网站上实现XML到HTML的转换(这是亚马逊在LISP中实现其后端的时候)。我没有去。这是一个有点讽刺意味的事实,因为我正在为我们工作的公司制造并销售一个Common LISP环境。

#15


1  

Another "real-world" language that implements functional programming features is Javascript. Since absolutely everything has a value, then high-order functions are easily implemented. You also have other tenants of functional programming such as lambda functions, closures, and currying.

另一种实现函数式编程功能的“真实世界”语言是Javascript。由于绝对一切都有价值,因此很容易实现高阶函数。您还有其他功能编程租户,例如lambda函数,闭包和currying。

#16


0  

The features you refer to ("powerful" macros, the code-as-data thing and custom control structures) have not propagated within other functional languages. They died after Lisp taught us that they are a bad idea.

您引用的功能(“强大的”宏,代码作为数据的东西和自定义控件结构)没有在其他函数语言中传播。 Lisp告诉我们他们是个坏主意后,他们死了。

Modern functional languages (OCaml, Haskell, Erlang, Scala, F#, C# 3.0, JavaScript) do not have those features.

现代函数式语言(OCaml,Haskell,Erlang,Scala,F#,C#3.0,JavaScript)没有这些功能。

Cheers, Jon Harrop.

干杯,Jon Harrop。