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

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

问题描述

我在互联网上搜索了 F#Haskell 但还没有找到任何真正确定的东西.主要区别是什么?为什么我要选择一个而不是另一个?

I've searched on the Internet for comparisons between 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 是一种纯粹的"函数式语言,而 F# 具有命令式/OO 和函数式语言的各个方面.Haskell 也有惰性求值,这在函数式语言中相当罕见.

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.

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

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.

惰性求值是指函数在绝对需要之前不会被求值.这意味着在不必要时可以避免许多操作.在基本的 C# if 子句中考虑这一点,例如:

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;
}

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

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

虽然 Haskell 是一种了不起的语言,但 F#(目前)的主要优点是它位于 CLR 之上.这使它适合多语言编程.有一天,您可能会在 ASP.net MVC 中编写 Web UI,在 C# 中编写业务逻辑,在 F# 中编写核心算法,在 Ironruby 中编写单元测试......所有这些都包含在 .Net 框架中.

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.

收听 Simon Peyton Jones 的软件工程广播,了解有关 Haskell 的更多信息:第 108 集:Simon Peyton Jones 关于函数式编程和 Haskell

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天全站免登陆