Haskell和F#之间的主要区别是什么? [英] What are the primary differences between Haskell and F#?

查看:170
本文介绍了Haskell和F#之间的主要区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Internet上搜索了 F# Haskell ,但还没有找到真正确定的东西.主要区别是什么?为什么我要选择一个?

解决方案

Haskell是一种纯"功能语言,在F#中,它同时具有命令性/OO语言和功能性语言的方面. Haskell也有惰性评估,这在功能语言中很少见.

这些东西是什么意思?纯函数式语言表示没有副作用(或在调用函数时共享状态发生变化),这意味着可以保证,如果调用f(x),则除了从函数中返回值外,不会发生任何其他事情,例如控制台输出,数据库输出,对全局或静态变量的更改..尽管Haskell可以具有非纯函数(通过monad),但必须通过声明明确地"隐含它.

纯函数语言和无副作用"编程最近很流行,因为它很适合多核并发,因为没有共享状态而不是无数的锁和错误更容易出错.信号量.

懒惰求值是在绝对必要之前才对函数求值的地方.意味着在不必要时可以避免许多操作.在基本的C#if子句中考虑以下内容:

if(IsSomethingTrue() && AnotherThingTrue())
{
    do something;
}

如果IsSomethingTrue()为false,则永远不会评估AnotherThingTrue()方法.

虽然Haskell是一种了不起的语言,但F#(暂时)的主要好处是它位于CLR之上.这使其很容易进行多语言编程.有一天,您可以在ASP.net MVC中编写Web UI,在C#中编写业务逻辑,在F#中编写核心算法,并在Ironruby中编写单元测试....

与Simon Peyton Jones收听软件工程电台,以获取有关Haskell的更多信息:F# and Haskell but haven't found anything really definitive. What are the primary differences and why would I want to choose one over the other?

解决方案

Haskell is a "pure" functional language, where as F# has aspects of both imperative/OO and functional languages. Haskell also has lazy evaluation, which is fairly rare amongst functional languages.

What do these things mean? A pure functional language, means there are no side effects (or changes in shared state, when a function is called) which means that you are guaranteed that if you call f(x), nothing else happens besides returning a value from the function, such as console output, database output, changes to global or static variables.. and although Haskell can have non pure functions (through monads), it must be 'explicitly' implied through declaration.

Pure functional languages and 'No side effect' programming has gained popularity recently as it lends itself well to multi core concurrency, as it is much harder to get wrong with no shared state, rather than myriad locks & semaphores.

Lazy evaluation is where a function is NOT evaluated until it is absolutely necessary required. meaning that many operation can be avoided when not necessary. Think of this in a basic C# if clause such as this:

if(IsSomethingTrue() && AnotherThingTrue())
{
    do something;
}

If IsSomethingTrue() is false then AnotherThingTrue() method is never evaluated.

While Haskell is an amazing language, the major benefit of F# (for the time being), is that it sits on top of the CLR. This lends it self to polyglot programming. One day, you may write your web UI in ASP.net MVC, your business logic in C#, your core algorithms in F# and your unit tests in Ironruby.... All amongst the the .Net framework.

Listen to the Software Engineering radio with Simon Peyton Jones for more info on Haskell: Episode 108: Simon Peyton Jones on Functional Programming and Haskell

这篇关于Haskell和F#之间的主要区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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