简体   繁体   English

哪些语言实现了功能编程的功能?

[英]What languages implement features from functional programming?

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#开关那样残缺)和咖喱函数,在常规程序设计中似乎显然有用,并且应该易于与现有程序设计实践相集成,但是由于某种原因,它似乎永远留在学术界。

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中学习的现代实用语言,而不是半信半疑地复制“一流的功能”,还是有固有的冲突使之不可能?

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#不是现代的?

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. 但是反之亦然-例如,(某些)功能语言具有对象。

Scala is a cool functional/OO language with pattern matching, first class functions, and the like. Scala是一种很酷的功能/ OO语言,具有模式匹配,一流的功能等。 It has the advantage of compiling to Java bytecode and inter-operates well with Java code. 它具有可编译为Java字节码并与Java代码良好互操作的优点。

I suggest you try Clojure . 我建议您尝试Clojure Syntactically beautiful dialect, functional (in the ML sense), and fast . 语法上漂亮的方言,实用的功能(在ML意义上)且快速 You get immutability, software transactional memory, multiversion concurrency control, a REPL, SLIME support, and an inexhaustible FFI. 您将获得不变性,软件事务存储,多版本并发控制,REPL,SLIME支持和不竭的FFI。 It's the Lisp (& Haskell) for the Business Programmer. 这是业务程序员的Lisp(&Haskell)。 I'm having a great time using it daily in my real job. 我在每天的真实工作中度过了愉快的时光。

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. 我们知道,与艺术家B相比,艺术家A受过更多的训练,并且创作的作品更具广度和深度,但艺术家B在市场上的成功要大得多。 Is it because there's a zeitgeist? 是因为有一个时代精神吗? Is is because artist B has better marketing? 是因为艺术家B有更好的营销? Is it because most people won't take the time to understand artist A? 是否因为大多数人不花时间去了解艺术家A? Maybe artist B is secretly awful and we should mistrust experts who make judgements about artists? 也许艺术家B暗中可怕,我们应该不信任对艺术家做出判断的专家吗? Probably all of the above, to some degree or another. 以上可能在某种程度上还是以上所有。

This drives people who study the arts, and people who study programming languages, crazy. 这驱使学习艺术的人们和学习编程语言的人们疯狂。

我猜想,在现实世界中使用的Common Lisp并不是那么疯狂。

Python or Ruby. Python或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?". 在问题“我喜欢Lisp但我的公司不允许我使用它。我应该怎么办?”的问题中,请参阅Paul Graham的想法

Scala is the absolute king of languages which have adopted significant academic features. Scala是采用重要学术特征的语言的绝对之王。 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. 更高种类,自我类型,多态模式匹配等。所有这些都是尖端的(或接近它)学术研究主题,已作为基本功能并入Scala。 Arguably, this has been to the detriment of the langauge's simplicity, but it does lead to some very interesting patterns. 可以说,这损害了语言的简单性,但确实导致了一些非常有趣的模式。

C# is more mainstream than Scala, but it also has adopted fewer of these "out-there" functional features. C#比Scala更主流,但是C#所采用的“外部”功能较少。 LINQ is a limited implementation for Wadler's generalized list comprehensions, and everyone knows about lambdas. LINQ对于Wadler的广义列表理解是有限的实现,并且每个人都知道lambda。 But for all that, C# (rightfully) remains a bit conservative in adopting research features from the academic world. 但是尽管如此,C#(理所当然)在采用学术界的研究功能时仍然有些保守。

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. 最近,Erlang不仅通过被Twitter使用,而且通过XMPP驱动的消息传递和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. 最初用于运行电话交换机,并由Ericson设想用于运行第一个GSM网络。 It is still around, it is fully functional (as a language) and used in many production environments. 它仍然存在,它具有完整的功能(作为一种语言),并在许多生产环境中使用。

Lua. a

It's used as a scripting/extension language for a number of games (like World of Worcraft), and applications (Snort, NMAP, Wireshark, etc). 它被用作许多游戏(如《魔兽世界》)和应用程序(Snort,NMAP,Wireshark等)的脚本/扩展语言。 In fact, according to an Adobe developer, Adobe's Lightroom is over 40% Lua. 实际上,根据Adobe开发人员的说法,Adobe的Lightroom占Lua的40%以上。

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。

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). 在2000年左右,我想使用LISP在我们的公司网站上实现XML到HTML的转换(这是在Amazon在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 . 当我为之工作的公司制造并出售Common LISP环境时,这有点讽刺。

您是否已签出F#

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和函数式编程的思想。

C# 3.0 definitely does. C#3.0绝对可以。

C# now has C#现在有

  1. Lambda Expressions Lambda表达式
  2. Higher Order Functions 高阶函数
  3. Map / Reduce + Filter ( Folding?) to lists and all types which implement IEnumerable. 映射/缩小+过滤器(可折叠?)到列表以及实现IEnumerable的所有类型。
  4. LINQ LINQ
  5. Object + Collection Initializers. 对象+集合初始化器。

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等实现了许多有用的概念。

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. 除了所说的以外,LISP的许多优点还基于保证没有副作用并使用内置数据结构。 Both rarely hold in real world. 两者在现实世界中很少见。 ML is probably better functional base. ML可能是更好的功能基础。

Another "real-world" language that implements functional programming features is Javascript. 实现功能编程功能的另一种“现实世界”语言是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. 您还具有其他函数式编程租户,例如lambda函数,闭包和curring。

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. 干杯,乔恩·哈罗普。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM