我在这里看到很多关于函数式语言的讨论。为什么你要使用传统语言而不是传统语言呢?他们在哪些方面做得更好?他们更不擅长什么?理想的函数式编程应用程序是什么?


当前回答

我一直对“下一件大事”持怀疑态度。很多时候,下一个大事件纯粹是历史的偶然,无论技术好坏,它都在正确的时间出现在正确的地点。例如:c++, Tcl/Tk, Perl。所有的技术都是有缺陷的,都非常成功,因为它们被认为要么解决了当时的问题,要么与根深蒂固的标准几乎相同,或者两者兼而有之。函数式编程可能确实很棒,但这并不意味着它会被采用。

But I can tell you why people are excited about functional programming: many, many programmers have had a kind of "conversion experience" in which they discover that using a functional language makes them twice as productive (or maybe ten times as productive) while producing code that is more resilient to change and has fewer bugs. These people think of functional programming as a secret weapon; a good example of this mindset is Paul Graham's Beating the Averages. Oh, and his application? E-commerce web apps.

自2006年初以来,也有一些关于函数式编程和并行的讨论。因为像Simon Peyton Jones这样的人至少从1984年开始就一直在担心并行性,所以在函数式语言解决多核问题之前,我不会屏住呼吸。但它确实解释了目前一些额外的话题。

In general, American universities are doing a poor job teaching functional programming. There's a strong core of support for teaching intro programming using Scheme, and Haskell also enjoys some support there, but there's very little in the way of teaching advanced technique for functional programmer. I've taught such a course at Harvard and will do so again this spring at Tufts. Benjamin Pierce has taught such a course at Penn. I don't know if Paul Hudak has done anything at Yale. The European universities are doing a much better job; for example, functional programming is emphasized in important places in Denmark, the Netherlands, Sweden, and the UK. I have less of a sense of what's happening in Australasia.

其他回答

你最近有关注编程语言的发展吗?所有主流编程语言的每一个新版本似乎都从函数式编程中借用了越来越多的特性。

Closures, anonymous functions, passing and returning functions as values used to be exotic features known only to Lisp and ML hackers. But gradually, C#, Delphi, Python, Perl, Javascript, have added support for closures. Its not possible for any up-and-coming language to be taken seriously without closures. Several languages, notably Python, C#, and Ruby have native support for list comprehensions and list generators. ML pioneered generic programming in 1973, but support for generics ("parametric polymorphism") has only become an industry standard in the last 5 years or so. If I remember correctly, Fortran supported generics in 2003, followed by Java 2004, C# in 2005, Delphi in 2008. (I know C++ has supported templates since 1979, but 90% of discussions on C++'s STL start with "here there be demons".)

是什么让这些功能吸引程序员?这应该是显而易见的:它帮助程序员编写更短的代码。如果想要保持竞争力,未来所有的语言都将至少支持闭包。在这方面,函数式编程已经成为主流。

大多数应用程序都很简单 可以用正常的面向对象方法解决

谁说不能用函数式编程来处理简单的事情?并不是每个函数程序都需要是编译器、定理证明器或大型并行通信交换机。除了更复杂的项目外,我还经常使用f#来编写临时脚本。

我同意第一点,但是时代变了。公司会做出回应,即使他们是后期采用者,如果他们看到有一个优势。生活是动态的。

90年代末,他们在斯坦福教授哈斯凯尔和ML。我相信卡内基梅隆大学、麻省理工学院、斯坦福大学和其他一些好学校正在向学生们展示它。

我同意大多数“在网络上公开关系数据库”的应用程序将在很长一段时间内继续这样做。对于这个问题,Java EE、. net、RoR和PHP已经演化出了一些非常好的解决方案。

您发现了一些重要的问题:这可能是其他方法无法轻松解决的问题,而这些方法将促进函数式编程。那是什么?

大规模多核硬件和云计算会推动它们向前发展吗?

我认为你问题的答案更多地在于“工作的正确工具”这句话,而不是最热门的东西。总会有热门的新技术,也总会有人扑上去。

函数式语言已经出现了一段时间,只是现在它们得到了更多的报道。

函数式语言的一个关键特征是一类函数的概念。其思想是,您可以将函数作为参数传递给其他函数,并将它们作为值返回。

函数式编程包括编写不改变状态的代码。这样做的主要原因是,对函数的连续调用将产生相同的结果。您可以使用任何支持第一类函数的语言编写函数式代码,但有一些语言(如Haskell)不允许更改状态。事实上,你根本不应该产生任何副作用(比如打印文本)——这听起来可能完全没用。

相反,Haskell对IO: monads采用了不同的方法。这些对象包含解释器顶层要执行的所需IO操作。在其他任何层面上,它们都只是系统中的对象。

函数式编程有什么优点?函数式编程允许代码出现错误的可能性更小,因为每个组件都是完全隔离的。此外,使用递归和一级函数允许简单的正确性证明,这通常反映了代码的结构。

它已经在Hadoop中的Map/reduce中流行起来