.net 创建 F# 语言是为了完成什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5642481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:28:06  来源:igfitidea点击:

What is the F# language created to accomplish?

.netf#

提问by Edward

I have noticed more and more a growing number of resources for developing applications using the F# programming language and the question came to mind of what the F# language was created to accomplish. Is it made for a specific platform, for example, Desktop, Mobile Devices, Web Applications? Also, did it include features not available in other programming languages that are currently available for developing .NET applications? Also is it still possible to create applications for the desktop, mobile, and web using F# as we can use VB or C#? Also, are there other languages similar to F# that I can use to cross-check against to get a better understanding of how functional programming works?

我注意到越来越多的资源用于使用 F# 编程语言开发应用程序,并且我想到了创建 F# 语言是为了完成什么的问题。它是否针对特定平台,例如桌面、移动设备、Web 应用程序?此外,它是否包括目前可用于开发 .NET 应用程序的其他编程语言所不具备的功能?是否仍然可以像使用 VB 或 C# 一样使用 F# 为桌面、移动设备和 Web 创建应用程序?另外,是否有其他类似于 F# 的语言可以用来交叉检查以更好地理解函数式编程的工作原理?

回答by petebu

What is the F# language created to accomplish?

创建 F# 语言是为了完成什么?

The F# research project sought to create a variant of the OCaml language running on top of the .Net platform. A related project at MSR Cambridge, SML.NET, did the same for Standard ML. (OCaml and Standard ML are both variants of the ML language.) The motivations for this might have included

F# 研究项目试图创建在 .Net 平台上运行的 OCaml 语言的变体。MSR Cambridge 的一个相关项目 SML.NET 对标准机器学习做了同样的事情。(OCaml 和标准 ML 都是 ML 语言的变体。)这样做的动机可能包括

  1. Showing it can be done.
  2. Publishing scientific papers showing it can be done.
  3. Because ML is incredibly cool.
  1. 显示它是可以做到的。
  2. 发表科学论文表明这是可以做到的。
  3. 因为 ML 非常酷。

This shouldn't distract you from the fact that the F# product is a general-purpose programming language for the .Net platform. The benefits of F# extend across all domains. There may be users who are adopting F# more rapidly - scientific and financial programming are often mentioned - but the real reason for that is because those organizations are more amenable to adopting new technology (small teams, smart people, few managers).

这不应分散您对 F# 产品是 .Net 平台的通用编程语言这一事实​​的注意力。F# 的好处扩展到所有域。可能有些用户更快地采用 F#——经常提到科学和金融编程——但真正的原因是因为这些组织更愿意采用新技术(小团队、聪明的人、很少的经理)。

Is it made for a specific platform for example Desktop, Mobile Devices, Web Applications?

它是为特定平台(例如桌面、移动设备、Web 应用程序)制作的吗?

No.

不。

Also did it include features not available in other programming languages that are currently available for developing .NET applications?

它还包括目前可用于开发 .NET 应用程序的其他编程语言中没有的功能吗?

Yes. They include:

是的。它们包括:

  • Algebraic datatypes
  • Pattern matching
  • Type inference
  • Succinct syntax
  • Sequence expressions
  • Asynchronous workflows
  • Units of measure
  • 代数数据类型
  • 模式匹配
  • 类型推断
  • 简洁的语法
  • 序列表达式
  • 异步工作流
  • 计量单位

Also is it still possible to create applications for the desktop, mobile, and web using F# as we can using VB or C#?

是否仍然可以像使用 VB 或 C# 一样使用 F# 为桌面、移动设备和 Web 创建应用程序?

Yes but the tooling in VS2010 is incomplete. In particular, anything involving code-generation isn't well supported e.g. WPF code-behind and the Winforms designer. This may not be a problem in practice. For instance WPF with MVVM works fairly well.

是的,但 VS2010 中的工具不完整。特别是,任何涉及代码生成的东西都没有得到很好的支持,例如 WPF 代码隐藏和 Winforms 设计器。这在实践中可能不是问题。例如,带有 MVVM 的 WPF 工作得相当好。

Also are there other languages similar to F# that I can use to cross check against to get a better understanding how functional programming works?

还有其他类似于 F# 的语言可以用来交叉检查以更好地理解函数式编程的工作原理吗?

Yes. Have a look at these:

是的。看看这些:

  • Standard ML
  • OCaml
  • Haskell
  • Clojure
  • 标准机器学习
  • OCaml
  • 哈斯克尔
  • Clojure

[Edit: Added comment about tooling in VS2010.]

[编辑:在 VS2010 中添加了关于工具的评论。]

回答by Mark Cidade

F# was created to bring a functional programming language to .NET.

F# 的创建是为了将函数式编程语言引入 .NET。

It isn't intended for any particular platform. According to Microsoft Research, it "has particular strengths in data-oriented programming, parallel I/O programming, parallel CPU programming, scripting and algorithmic development". F# is used for financial and scientific applications in particular.

它不适用于任何特定平台。根据微软研究院的说法,它“在面向数据的编程、并行 I/O 编程、并行 CPU 编程、脚本和算法开发方面具有特殊的优势”。F# 尤其用于金融和科学应用程序。

C# was created for Microsoft to have a modern C-like language since they were restricted from extending Java to take advantage of Windows. It was designed to be a component-oriented language and isn't specialized for the Web in any way.

C# 是为微软创建的,目的是为了拥有一种现代的类 C 语言,因为它们被限制扩展 Java 以利用 Windows。它被设计为一种面向组件的语言,并没有以任何方式专门用于 Web。

F# is primarily a functional language whereas C# and VB are both primarily object-oriented.

F# 主要是一种函数式语言,而 C# 和 VB 都主要是面向对象的。

See also:

也可以看看:

回答by James Black

When trying to take advantage of ideas from functional programming, such as the focus on immutability, and optimizations that can come from this, including using tail-end recursion, you will find that it is possible to improve the readability of the code, improving on maintainability.

当试图利用函数式编程的思想,比如对不变性的关注,以及由此产生的优化,包括使用尾端递归,你会发现可以提高代码的可读性,改进可维护性。

But, by using a language such as F# is makes it easier to do language-oriented programming (http://en.wikipedia.org/wiki/Language-oriented_programming), as you create domain-specific languages, so, for example, you can write a small language for a chemist where they use the terms they are familiar with to write equations, or to model molecules, and the program can parse that and react with the expected behavior.

但是,通过使用诸如 F# 之类的语言,可以更轻松地进行面向语言的编程 ( http://en.wikipedia.org/wiki/Language-orientation_programming),因为您创建了特定领域的语言,因此,例如,您可以为化学家编写一种小型语言,让他们使用他们熟悉的术语来编写方程式或对分子进行建模,然后程序可以对其进行解析并对预期行为做出反应。

Because C# is so object-oriented, it makes it harder to have the language be so simple to use, as, in F# you can skip the '.' in method calls, so Jacob buys 100 shares of IBMbecause a series of function calls.

由于 C# 是面向对象的,因此很难让语言如此简单易用,因为在 F# 中,您可以跳过“.”。在方法调用中,Jacob buys 100 shares of IBM因为一系列的函数调用。

Concurrency is simpler due to some of the constructs, such as previously mentioned immutability, so, some of the features we see in F# will probably help improve on C#.

由于某些构造(例如前面提到的不变性),并发性更简单,因此,我们在 F# 中看到的某些功能可能有助于改进 C#。

So, F# helps MS to get into areas, such as science programming and modeling, as it is better than C# for these, due to these and other benefits from the language.

因此,F# 帮助 MS 进入科学编程和建模等领域,因为在这些方面它比 C# 更好,因为该语言具有这些和其他好处。

But, you can also use the .NET assemblies, and if you write your code well, you can do the math intensive parts in F# and have C# or VB.NET call your functions, so we can use the best language for each task.

但是,您也可以使用 .NET 程序集,如果您的代码编写得很好,您可以在 F# 中完成数学密集型部分,并让 C# 或 VB.NET 调用您的函数,因此我们可以为每个任务使用最好的语言。

UPDATE:

更新:

After reading some of the new comments, one area that has become a problem is how to write good code that takes advantage of multi-core CPUs. So, functional programming has become more popular, as seen by F#, Scala, Clojure, naming just a few, so MS went into this to help programmers take better advantage of the new chip architectures.

在阅读了一些新评论后,一个成为问题的领域是如何编写利用多核 CPU 的好代码。因此,函数式编程变得越来越流行,正如 F#、Scala、Clojure 所见,仅举几例,因此 MS 进入这一领域是为了帮助程序员更好地利用新的芯片架构。

回答by Edward

I have found some resources that touched on my question:

我找到了一些触及我的问题的资源:

What & Why Choose F#?

什么以及为什么选择 F#?

How will F# be used?

F# 将如何使用?

Nine reasons to use F#

使用 F# 的九个理由

Why should I use F#?

为什么要使用 F#?

When does it make sense to use F# over C# or VB.NET

什么时候在 C# 或 VB.NET 上使用 F# 有意义

From what it looks like there is no clear answer as is usually when trying to determine to use a particular language. Although I have never used functional programming before from some of the examples I have seen it can be extremely useful. It seems like another great option when developing .NET applications.

从表面上看,在尝试确定使用特定语言时,通常没有明确的答案。尽管我之前从未使用过一些示例中的函数式编程,但它非常有用。在开发 .NET 应用程序时,这似乎是另一个不错的选择。

回答by Conrad Frix

If you watch this videoby Don Syme maybe you'll get some of the answers you're looking for.

如果您观看Don Syme 的这个视频,也许您会得到一些您正在寻找的答案。

updateAfter watching the video it would seem that he created it because at the time (1998) he didn't like Java or what he saw of C# but liked functional programming like OCaml. Since he worked for MS research he wrote F#.

更新观看视频后,他创建它似乎是因为当时(1998 年)他不喜欢 Java 或他所看到的 C#,但喜欢像 OCaml 这样的函数式编程。由于他为 MS 研究工作,他编写了 F#。

I imagine the genisis of a number of languages that target the cli (A#, ronPython, IronRuby, etc) are similar.

我想许多针对 cli(A#、ronPython、IronRuby 等)的语言的起源是相似的。