什么是Haskell实际上有用的? [英] What is Haskell actually useful for?

查看:168
本文介绍了什么是Haskell实际上有用的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我开始学习Haskell,我可以找到自己使用它的原因。我听说这种语言的一些常见用途是功能性的

解决方案


这种
语言的常见用途是什么?


快速应用程序开发。



如果您想知道为什么Haskell?,那么您需要考虑函数式编程语言的优点(摘自 http://c2.com/cgi/wiki?AdvantageOfFunctionalProgramming ):



  • 函数式程序往往比其ImperativeLanguage对应语言更为简洁。通常这会提高
    程序员的工作效率。


  • FP鼓励快速原型设计。因此,我认为这是ExtremeProgrammers的最佳软件设计范例......但我知道什么?


  • FP在功能维度上是模块化的,其中ObjectOrientedProgramming在不同
    组件的维度中是模块化的。


  • 具有蛋糕和吃它的能力。想象一下,你有一个复杂的面向对象系统处理消息 - 每个组件可能会使状态
    根据消息而变化,然后将消息转发给它链接到的一些
    对象。如果
    层次中的某个对象决定信息有缺陷,那么能不能通过
    轻松地回滚每一项更改会不会太酷?如何获得
    不同状态的历史?

  • 为您制作的许多内务任务:解构数据结构(PatternMatching),存储变量绑定(LexicalScope
    closures),强类型(TypeInference),GarbageCollection,存储
    分配,是否使用boxed(指向值)或unboxed(value
    直接)表示形式...
    p>


  • 安全的多线程!不可变的数据结构不受数据竞争条件的影响,因此不必受
    锁保护。如果您始终分配新对象,而不是
    破坏性地操作现有对象,那么锁定可以隐藏在
    分配和GarbageCollection系统中。


>

除此之外,Haskell还有其自身的优势,如:



  • 列出解析来创建基于现有列表的列表。

  • Lambda表达式:创建函数没有给他们明确的名字。所以处理大公式更容易。

  • Haskell完全是透明透明。任何使用I / O的代码都必须标记为这样。通过这种方式,它鼓励您将代码与副作用(例如,在屏幕上放置文本)从不带(计算)的代码中分离出来。

  • 懒惰评估是一个非常不错的功能:


    • 即使某些东西通常会导致错误,只要您不使用结果,它仍然会有效。例如,您可以将 1/0 作为列表的第一个项目,如果您只使用第二个项目,它仍然可以工作。

    • 编写搜索程序比较容易,例如数独求解器,因为它不会立即加载每个组合,它只是随着它而生成它们。你可以用其他语言来做到这一点,但只有Haskell默认做这个




您可以查看以下链接:


  • http://c2.com/cgi/wiki?AdvantageOfFunctionalProgramming

  • http://blogs.msdn.com /wesdyer/archive/2007/01/18/why-functional-programming-is-important-in-a-mixed-environment.aspx

  • http://blog.kickino.org/archives/2007/05/22/T22_34_16/

  • http ://useless-factor.blogspot.com/2007/05/advantage-of-functional-programming.html

  • ul>

    For instance, if I start learning Haskell, what can I find myself using it for. What are some common uses for this language that I hear is a functional one?

    解决方案

    What are some common uses for this language?

    Rapid application development.

    If you want to know "why Haskell?", then you need to consider advantages of functional programming languages (taken from http://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.

    Apart from this Haskell has its own advantages such as:

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

    You can check out following links:

    这篇关于什么是Haskell实际上有用的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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