如何使用f# (sharp) ?

时间:2022-09-11 10:27:12

I'm having trouble placing the concepts and possiblities of the to be introduced F# language from Microsoft.

我在把从微软引入f#语言的概念和可能性放在一起时遇到了麻烦。

Will F# be used just for declaring functions? Or will applications be written 'entirely' in F# by mixing F# together with normal C# or VB code?

f#仅仅用于声明函数吗?或者将f#与普通c#或VB代码混合,将应用程序“完全”写在f#中?

8 个解决方案

#1


23  

My expectation is that F# will be used for pieces of some specialized systems - the bits that involve complex threading / maths / financial / modelling / etc, where F# does well. For most other areas (UI, DAL, etc), a general purpose language like C# seems (IMO) preferable.

我的期望是,f#将用于某些特定系统的各个部分——涉及复杂线程/数学/金融/建模等的部分,而f#在这些方面做得很好。对于大多数其他领域(UI、DAL等),像c#这样的通用语言似乎更可取。

One of the advantages of the F# is that (in theory) you can prove code is working, rather than just test it. The threading support (thanks to immutability and the async ! usage) is also good (although PLINQ may compete on threading).

f#的优点之一是(理论上)您可以证明代码是有效的,而不是仅仅测试它。线程支持(感谢不变性和异步!使用)也很好(尽管PLINQ可能会在线程上竞争)。

Hooking into .NET to allow proper integration between F#, C#, VB, IronPython, IronRuby, etc - really shows the strengths of each. Today if I was doing lots of COM interop, I'd consider VB (that'll change in 4.0 with dynamic); for most code - C#. For math etc, F#. Tidy.

连接到。net以允许f#、c#、VB、IronPython、IronRuby等之间进行适当的集成,这确实显示了它们各自的优势。今天如果我要做很多的COM互操作,我会考虑VB(在4.0中会有动态变化);对于大多数代码- c#。对于数学等,f#。整洁。

#2


35  

I can highly recommend you to watch Luca Bolognese's talk from PDC 2008. It's not only very entertaining but he also demonstrates quite impressive use cases of F#:

我强烈推荐你从2008年的PDC上观看Luca Bolognese的演讲。这不仅非常有趣,而且他还展示了f#令人印象深刻的用例:

An Introduction to Microsoft F# by Luca Bolognese

Luca Bolognese为您介绍微软f#

#3


8  

I've used it for half a year and I think it will become a general use language. It's fairly complex to learn so doubt it will be used too much in a mixed environment. Managers want to keep costs to a minimum.

我用了半年了,我想它会成为一种通用语言。这是相当复杂的学习,所以怀疑它将在混合环境中使用太多。管理者希望把成本降到最低。

  • Refactoring speed for me is F# biggest selling point. Having built a simple video game with it, i've fallen in love with the languages constructs. At first the idea of dealing with a state engine seemed out of place in a functional language however with records, tuples and type inference it makes for very fast changes.

    重构速度对我来说是最大的卖点。用它制作了一个简单的视频游戏后,我爱上了语言结构。起初,处理状态引擎的想法在函数语言中似乎不太合适,但是处理记录、元组和类型推断会导致非常快速的更改。

  • F# has good readability. Once your familiar with F#, if you allow for a mix of multi-paradigm programming styles, code becomes very terse and easy to read however like all languages someone who doesn't know what they are doing can turn it into a nightmare.

    f#具有良好的可读性。一旦你熟悉了f#,如果你允许多范式编程风格的混合,代码就会变得非常简洁和易于阅读,但是就像所有语言一样,不知道自己在做什么的人可能会把它变成一场噩梦。

My day job involves web prototyping, so I'm looking forward to see where FSharp.WebTools goes and to seeing more support for F# with Microsoft MVC.

我的日常工作涉及到web原型设计,所以我很期待看到FSharp在哪里。WebTools可以看到更多的支持f#和微软MVC。

#4


6  

I use F# in the following areas:

我在以下方面使用f#:

DLLs and libraries. Pretty much all the new code I write in my free time is F#, and I only reach for C# when I need a quick GUI.

dll和库。我在空闲时间编写的几乎所有新代码都是f#,我只在需要快速GUI时才使用c#。

Multitherading. At work, I've been slowly introducing F#. I got a chance to demonstrate what it can do by moving some ugly single-threaded VB.NET to multithreaded F# using async workflows and mailbox processors.

Multitherading。在工作中,我一直在慢慢地介绍f#。我有机会通过移动一些丑陋的单线程VB来演示它能做什么。NET到多线程f#,使用异步工作流和邮箱处理器。

DSLs and Parsing. At my last company, I used FsLex/FsYacc to parse SQL into an AST. A variation of the prototype code made it into this tutorial.

dsl和解析。在我的上一个公司,我使用FsLex/FsYacc来将SQL解析为一个AST。

Scripting. I totally <3 scripting with .fsx files. Their a handy way of writing small scripts without having to write a full-blown executable. Its also nice to modify the sourcecode and run it again with no downtime. I've modified the default behavior of .fsx files to run fsi rather than opening in VS when they're double-clicked.

脚本。我总共用.fsx文件编写了<3个脚本。这是一种编写小脚本的简便方法,无需编写完整的可执行文件。修改源代码并在不停机的情况下再次运行它也很好。我修改了.fsx文件的默认行为以运行fsi,而不是在双击时打开VS。

#5


3  

Certainly, it is feasible to write entire programs in F#. However, I think that most programs will not go this way. F# will most likely be used for the complex algorithms and application logic (the heart of the program), while C# will probably be used for the "outside" (the GUI, etc.). .NET is imperatively structured, so in places where you are using the libraries heavily, C# will probably be more "natural" than F#.

当然,用f#编写整个程序是可行的。然而,我认为大多数节目不会这样做。f#将最有可能被用于复杂的算法和应用程序逻辑(程序)的核心,而c#将可能被用于“外”(GUI等),. net是命令式地结构,所以在您使用库严重的地方,c#可能会比f#更“自然”。

#6


3  

Your question implies that all code eventually becomes an application.

您的问题意味着所有代码最终都将成为应用程序。

This is not necessarily the case though, and one of the strengths of F# (compared to C#, say), is that you can 'break out' your favourite IDE and just run bits of code, without all the Solution/Project/class infrastructure.

但这并不一定是这样,而且与c#相比,f#的优点之一是,您可以在不使用所有解决方案/项目/类基础设施的情况下,“跳出”您最喜欢的IDE并运行少量代码。

For number crunching test results, transforming data, testing out a new algorithm (even if I end up coding it in C# in the 'application'), sorting through log files, even creating a little utility to tell me how many of my C# references are actually being used in a given assembly, F# is nifty, quick, and yet rapidly 'scaleable' up to a dll if I decide to use it further.

数字运算的测试结果,转换数据,测试一种新的算法(即使我最终编码在c#中在“应用程序”),整理日志文件,甚至创建一个小工具来告诉我我的很多c#引用实际上是如何被用于给定的装配,f#是漂亮的,快速,但快速的可伸缩到dll进一步如果我决定使用它。

#7


2  

Depending on the context, you might consider both.

根据上下文,您可以同时考虑两者。

You can use F# to build complete .NET applications or hook it up to other .NET languages. It can consume and expose libraries from/to other .NET languages.

您可以使用f#来构建完整的。net应用程序,或者将其与其他。net语言连接起来。它可以从/到其他。net语言使用和公开库。

#8


1  

Will F# be used just for declaring functions? Or will applications be written 'entirely' in F# by mixing F# together with normal C# or VB code?

f#仅仅用于声明函数吗?或者将f#与普通c#或VB代码混合,将应用程序“完全”写在f#中?

We've been writing entire applications in F# for over 3 years. A lot of companies are augmenting their existing code bases with F#.

我们已经用f#编写整个应用程序超过3年了。许多公司都在使用f#扩展现有的代码库。

The easiest entry points for F# are things like shipping F# samples demonstrating how the API of the library you're selling can be used from F#. That is a no-brainer for any company because the samples are not mission critical so technical expertise and on-going maintenance are not an issue. F# is also a great tool for writing test harnesses for existing code in any .NET language. Again, the customer never gets that code so its reliability outside your company is not a concern. In practice, we've had no problems going gung-ho and using F# everywhere and shipping it to customers without them even knowing. That works particularly well for small companies because the massive productivity improvements give us a huge competitive advantage.

f#最简单的入口点是像发送f#样例演示如何从f#中使用您所出售的库的API。这对任何公司来说都是显而易见的,因为这些样品并不重要,所以技术专长和持续的维护都不是问题。f#也是一种很好的工具,可以为任何。net语言的现有代码编写测试工具。再说一遍,客户永远不会得到代码,所以它在公司之外的可靠性并不重要。在实践中,我们没有遇到任何问题,在任何地方都使用f#,甚至在不知情的情况下将其发送给客户。这对于小公司来说尤其有效,因为生产力的巨大提高给了我们巨大的竞争优势。

#1


23  

My expectation is that F# will be used for pieces of some specialized systems - the bits that involve complex threading / maths / financial / modelling / etc, where F# does well. For most other areas (UI, DAL, etc), a general purpose language like C# seems (IMO) preferable.

我的期望是,f#将用于某些特定系统的各个部分——涉及复杂线程/数学/金融/建模等的部分,而f#在这些方面做得很好。对于大多数其他领域(UI、DAL等),像c#这样的通用语言似乎更可取。

One of the advantages of the F# is that (in theory) you can prove code is working, rather than just test it. The threading support (thanks to immutability and the async ! usage) is also good (although PLINQ may compete on threading).

f#的优点之一是(理论上)您可以证明代码是有效的,而不是仅仅测试它。线程支持(感谢不变性和异步!使用)也很好(尽管PLINQ可能会在线程上竞争)。

Hooking into .NET to allow proper integration between F#, C#, VB, IronPython, IronRuby, etc - really shows the strengths of each. Today if I was doing lots of COM interop, I'd consider VB (that'll change in 4.0 with dynamic); for most code - C#. For math etc, F#. Tidy.

连接到。net以允许f#、c#、VB、IronPython、IronRuby等之间进行适当的集成,这确实显示了它们各自的优势。今天如果我要做很多的COM互操作,我会考虑VB(在4.0中会有动态变化);对于大多数代码- c#。对于数学等,f#。整洁。

#2


35  

I can highly recommend you to watch Luca Bolognese's talk from PDC 2008. It's not only very entertaining but he also demonstrates quite impressive use cases of F#:

我强烈推荐你从2008年的PDC上观看Luca Bolognese的演讲。这不仅非常有趣,而且他还展示了f#令人印象深刻的用例:

An Introduction to Microsoft F# by Luca Bolognese

Luca Bolognese为您介绍微软f#

#3


8  

I've used it for half a year and I think it will become a general use language. It's fairly complex to learn so doubt it will be used too much in a mixed environment. Managers want to keep costs to a minimum.

我用了半年了,我想它会成为一种通用语言。这是相当复杂的学习,所以怀疑它将在混合环境中使用太多。管理者希望把成本降到最低。

  • Refactoring speed for me is F# biggest selling point. Having built a simple video game with it, i've fallen in love with the languages constructs. At first the idea of dealing with a state engine seemed out of place in a functional language however with records, tuples and type inference it makes for very fast changes.

    重构速度对我来说是最大的卖点。用它制作了一个简单的视频游戏后,我爱上了语言结构。起初,处理状态引擎的想法在函数语言中似乎不太合适,但是处理记录、元组和类型推断会导致非常快速的更改。

  • F# has good readability. Once your familiar with F#, if you allow for a mix of multi-paradigm programming styles, code becomes very terse and easy to read however like all languages someone who doesn't know what they are doing can turn it into a nightmare.

    f#具有良好的可读性。一旦你熟悉了f#,如果你允许多范式编程风格的混合,代码就会变得非常简洁和易于阅读,但是就像所有语言一样,不知道自己在做什么的人可能会把它变成一场噩梦。

My day job involves web prototyping, so I'm looking forward to see where FSharp.WebTools goes and to seeing more support for F# with Microsoft MVC.

我的日常工作涉及到web原型设计,所以我很期待看到FSharp在哪里。WebTools可以看到更多的支持f#和微软MVC。

#4


6  

I use F# in the following areas:

我在以下方面使用f#:

DLLs and libraries. Pretty much all the new code I write in my free time is F#, and I only reach for C# when I need a quick GUI.

dll和库。我在空闲时间编写的几乎所有新代码都是f#,我只在需要快速GUI时才使用c#。

Multitherading. At work, I've been slowly introducing F#. I got a chance to demonstrate what it can do by moving some ugly single-threaded VB.NET to multithreaded F# using async workflows and mailbox processors.

Multitherading。在工作中,我一直在慢慢地介绍f#。我有机会通过移动一些丑陋的单线程VB来演示它能做什么。NET到多线程f#,使用异步工作流和邮箱处理器。

DSLs and Parsing. At my last company, I used FsLex/FsYacc to parse SQL into an AST. A variation of the prototype code made it into this tutorial.

dsl和解析。在我的上一个公司,我使用FsLex/FsYacc来将SQL解析为一个AST。

Scripting. I totally <3 scripting with .fsx files. Their a handy way of writing small scripts without having to write a full-blown executable. Its also nice to modify the sourcecode and run it again with no downtime. I've modified the default behavior of .fsx files to run fsi rather than opening in VS when they're double-clicked.

脚本。我总共用.fsx文件编写了<3个脚本。这是一种编写小脚本的简便方法,无需编写完整的可执行文件。修改源代码并在不停机的情况下再次运行它也很好。我修改了.fsx文件的默认行为以运行fsi,而不是在双击时打开VS。

#5


3  

Certainly, it is feasible to write entire programs in F#. However, I think that most programs will not go this way. F# will most likely be used for the complex algorithms and application logic (the heart of the program), while C# will probably be used for the "outside" (the GUI, etc.). .NET is imperatively structured, so in places where you are using the libraries heavily, C# will probably be more "natural" than F#.

当然,用f#编写整个程序是可行的。然而,我认为大多数节目不会这样做。f#将最有可能被用于复杂的算法和应用程序逻辑(程序)的核心,而c#将可能被用于“外”(GUI等),. net是命令式地结构,所以在您使用库严重的地方,c#可能会比f#更“自然”。

#6


3  

Your question implies that all code eventually becomes an application.

您的问题意味着所有代码最终都将成为应用程序。

This is not necessarily the case though, and one of the strengths of F# (compared to C#, say), is that you can 'break out' your favourite IDE and just run bits of code, without all the Solution/Project/class infrastructure.

但这并不一定是这样,而且与c#相比,f#的优点之一是,您可以在不使用所有解决方案/项目/类基础设施的情况下,“跳出”您最喜欢的IDE并运行少量代码。

For number crunching test results, transforming data, testing out a new algorithm (even if I end up coding it in C# in the 'application'), sorting through log files, even creating a little utility to tell me how many of my C# references are actually being used in a given assembly, F# is nifty, quick, and yet rapidly 'scaleable' up to a dll if I decide to use it further.

数字运算的测试结果,转换数据,测试一种新的算法(即使我最终编码在c#中在“应用程序”),整理日志文件,甚至创建一个小工具来告诉我我的很多c#引用实际上是如何被用于给定的装配,f#是漂亮的,快速,但快速的可伸缩到dll进一步如果我决定使用它。

#7


2  

Depending on the context, you might consider both.

根据上下文,您可以同时考虑两者。

You can use F# to build complete .NET applications or hook it up to other .NET languages. It can consume and expose libraries from/to other .NET languages.

您可以使用f#来构建完整的。net应用程序,或者将其与其他。net语言连接起来。它可以从/到其他。net语言使用和公开库。

#8


1  

Will F# be used just for declaring functions? Or will applications be written 'entirely' in F# by mixing F# together with normal C# or VB code?

f#仅仅用于声明函数吗?或者将f#与普通c#或VB代码混合,将应用程序“完全”写在f#中?

We've been writing entire applications in F# for over 3 years. A lot of companies are augmenting their existing code bases with F#.

我们已经用f#编写整个应用程序超过3年了。许多公司都在使用f#扩展现有的代码库。

The easiest entry points for F# are things like shipping F# samples demonstrating how the API of the library you're selling can be used from F#. That is a no-brainer for any company because the samples are not mission critical so technical expertise and on-going maintenance are not an issue. F# is also a great tool for writing test harnesses for existing code in any .NET language. Again, the customer never gets that code so its reliability outside your company is not a concern. In practice, we've had no problems going gung-ho and using F# everywhere and shipping it to customers without them even knowing. That works particularly well for small companies because the massive productivity improvements give us a huge competitive advantage.

f#最简单的入口点是像发送f#样例演示如何从f#中使用您所出售的库的API。这对任何公司来说都是显而易见的,因为这些样品并不重要,所以技术专长和持续的维护都不是问题。f#也是一种很好的工具,可以为任何。net语言的现有代码编写测试工具。再说一遍,客户永远不会得到代码,所以它在公司之外的可靠性并不重要。在实践中,我们没有遇到任何问题,在任何地方都使用f#,甚至在不知情的情况下将其发送给客户。这对于小公司来说尤其有效,因为生产力的巨大提高给了我们巨大的竞争优势。