有很多关于Haskell的宣传,然而,很难获得关于它如何在现实应用程序中使用的信息。Haskell最流行的项目/用法是什么?为什么它能出色地解决这些问题?
当前回答
它的一些常见用途是什么 语言吗?
快速应用程序开发。
如果你想知道“为什么是Haskell?”,那么你需要考虑函数式编程语言的优势(摘自https://c2.com/cgi/wiki?AdvantagesOfFunctionalProgramming):)
Functional programs tend to be much more terse than their ImperativeLanguage counterparts. Often this leads to enhanced programmer productivity FP encourages quick prototyping. As such, I think it is the best software design paradigm for ExtremeProgrammers... but what do I know? FP is modular in the dimension of functionality, where ObjectOrientedProgramming is modular in the dimension of different components. The ability to have your cake and eat it. Imagine you have a complex OO system processing messages - every component might make state changes depending on the message and then forward the message to some objects it has links to. Wouldn't it be just too cool to be able to easily roll back every change if some object deep in the call hierarchy decided the message is flawed? How about having a history of different states? Many housekeeping tasks made for you: deconstructing data structures (PatternMatching), storing variable bindings (LexicalScope with closures), strong typing (TypeInference), GarbageCollection, storage allocation, whether to use boxed (pointer-to-value) or unboxed (value directly) representation... Safe multithreading! Immutable data structures are not subject to data race conditions, and consequently don't have to be protected by locks. If you are always allocating new objects, rather than destructively manipulating existing ones, the locking can be hidden in the allocation and GarbageCollection system.
除此之外,Haskell还有自己的优势,比如:
Clear, intuitive syntax inspired by mathematical notation. List comprehensions to create a list based on existing lists. Lambda expressions: create functions without giving them explicit names. So it's easier to handle big formulas. Haskell is completely referentially transparent. Any code that uses I/O must be marked as such. This way, it encourages you to separate code with side effects (e.g. putting text on the screen) from code without (calculations). Lazy evaluation is a really nice feature: Even if something would usually cause an error, it will still work as long as you don't use the result. For example, you could put 1 / 0 as the first item of a list and it will still work if you only used the second item. It is easier to write search programs such as this sudoku solver because it doesn't load every combination at once—it just generates them as it goes along. You can do this in other languages, but only Haskell does this by default.
你可以查看以下连结:
https://c2.com/cgi/wiki?AdvantagesOfFunctionalProgramming https://learn.microsoft.com/archive/blogs/wesdyer/why-functional-programming-is-important-in-a-mixed-environment https://web.archive.org/web/20160626145828/http://blog.kickino.org/archives/2007/05/22/T22_34_16/ https://useless-factor.blogspot.com/2007/05/advantage-of-functional-programming.html
其他回答
它的一些常见用途是什么 语言吗?
快速应用程序开发。
如果你想知道“为什么是Haskell?”,那么你需要考虑函数式编程语言的优势(摘自https://c2.com/cgi/wiki?AdvantagesOfFunctionalProgramming):)
Functional programs tend to be much more terse than their ImperativeLanguage counterparts. Often this leads to enhanced programmer productivity FP encourages quick prototyping. As such, I think it is the best software design paradigm for ExtremeProgrammers... but what do I know? FP is modular in the dimension of functionality, where ObjectOrientedProgramming is modular in the dimension of different components. The ability to have your cake and eat it. Imagine you have a complex OO system processing messages - every component might make state changes depending on the message and then forward the message to some objects it has links to. Wouldn't it be just too cool to be able to easily roll back every change if some object deep in the call hierarchy decided the message is flawed? How about having a history of different states? Many housekeeping tasks made for you: deconstructing data structures (PatternMatching), storing variable bindings (LexicalScope with closures), strong typing (TypeInference), GarbageCollection, storage allocation, whether to use boxed (pointer-to-value) or unboxed (value directly) representation... Safe multithreading! Immutable data structures are not subject to data race conditions, and consequently don't have to be protected by locks. If you are always allocating new objects, rather than destructively manipulating existing ones, the locking can be hidden in the allocation and GarbageCollection system.
除此之外,Haskell还有自己的优势,比如:
Clear, intuitive syntax inspired by mathematical notation. List comprehensions to create a list based on existing lists. Lambda expressions: create functions without giving them explicit names. So it's easier to handle big formulas. Haskell is completely referentially transparent. Any code that uses I/O must be marked as such. This way, it encourages you to separate code with side effects (e.g. putting text on the screen) from code without (calculations). Lazy evaluation is a really nice feature: Even if something would usually cause an error, it will still work as long as you don't use the result. For example, you could put 1 / 0 as the first item of a list and it will still work if you only used the second item. It is easier to write search programs such as this sudoku solver because it doesn't load every combination at once—it just generates them as it goes along. You can do this in other languages, but only Haskell does this by default.
你可以查看以下连结:
https://c2.com/cgi/wiki?AdvantagesOfFunctionalProgramming https://learn.microsoft.com/archive/blogs/wesdyer/why-functional-programming-is-important-in-a-mixed-environment https://web.archive.org/web/20160626145828/http://blog.kickino.org/archives/2007/05/22/T22_34_16/ https://useless-factor.blogspot.com/2007/05/advantage-of-functional-programming.html
对于像Haskell这样的通用语言的优点,有一个很好的答案:编写一般的程序。
对于它在实践中的用途,我有三种方法来建立它:
Haskell库和应用程序区域的标记云,根据Hackage上的频率加权。
表明它适用于图形、网络、系统编程、数据结构、数据库、开发、文本处理……
它在工业领域的应用——很多dsl, web应用程序,编译器设计,网络,分析,系统编程,…
最后,我认为它真正的强项是:
正确性很重要的问题,领域特定的语言,并行和并发编程
我希望这能让你知道你的问题有多宽泛,如果要具体回答的话。
我认为,对于从未使用过函数式编程语言的人来说,这篇文章中的人忽略了最重要的一点:扩展你的思维。如果你是函数式编程的新手,那么Haskell会让你以以前从未想过的方式思考。因此,您在其他领域和其他语言的编程将得到改进。多少钱?很难量化。
Haskell的一个例子是xmonad,一个“用不到1200行代码的功能强大的窗口管理器”。
Haskell是一种通用编程语言。它可以用于任何你使用其他语言做的事情。除了你自己的想象力,你不受任何东西的限制。至于它适合做什么呢?嗯,几乎所有的事情。几乎没有什么任务是函数式语言不擅长的。
没错,我是Dreamincode的Rayne。:)
我还想提一下,如果你还没有阅读维基百科页面,函数式编程是一种范式,就像面向对象编程是一种范式一样。以防你不知道。Haskell在某种意义上也是功能性的;它在这方面做得很好。
仅仅因为一种语言不是面向对象的语言并不意味着该语言受到任何东西的限制。Haskell是一种通用编程语言,和Java一样通用。
推荐文章
- 流行语言的语言书籍/教程
- 面向对象编程,函数式编程,过程式编程
- 获取与模板Haskell关联的类型同义词
- Haskell:列表,数组,向量,序列
- 按返回类型重载函数?
- 推挽型FRP和箭头型FRP有什么本质区别?
- 为什么不可变性在JavaScript中如此重要(或需要)?
- Template Haskell有什么不好的?
- 如何使用underscore.js作为模板引擎?
- Scala中的“提升”是什么?
- Javascript相当于Python的zip函数
- 感叹号在Haskell声明中是什么意思?
- 使用array_map()访问第一级键,而不调用' array_keys() '
- functools partial是怎么做的呢?
- 过程式编程和函数式编程的区别是什么?