gpt4 book ai didi

multithreading - F# 是函数式语言的糟糕选择吗

转载 作者:行者123 更新时间:2023-12-03 13:13:55 24 4
gpt4 key购买 nike

就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the help center寻求指导。




11年前关闭。




对我来说,我认为 F# 是一个糟糕的选择,因为它在后台使用线程。对我来说,由于上下文切换之类的原因,线程太“重”了。

我明白为什么 Erlang 是一个不错的选择,因为它使用轻量级进程。

我错了吗?

最佳答案

我不明白你在问什么。

F# 不使用“幕后线程”,或者至少不使用任何 .NET 进程。事实上 F# 的 async工具使编写不消耗线程的非阻塞 I/O 程序变得更加容易(与具有更困难的无线程/非阻塞编程模型的 C#/VB 相比)。

(当然,通常您不会只选择一个任意方面来比较两件事,然后决定“X 优于 Y”。编程语言不仅仅是线程/进程模型。)

你可能会喜欢阅读

http://blogs.msdn.com/dsyme/archive/2010/02/15/async-and-parallel-design-patterns-in-f-part-3-agents.aspx

最后三段值得引用:

Indeed, there are few other .NET or JVM-based languages that support lightweight reactive agents at all – in early .NET it was said to be “impossible” because of the costs of threads. In this context, F#’s integration of “async { ... }” in 2007 can be seen as somewhat of a breakthrough in applied language design – it allows lightweight, compositional async programming and reactive agents in the context of an industrially accepted and interoperable programming platform. Along with the Axum language prototype (which has been influential on F#), F# has proven that an asynchronous language feature is a feasible way to break through the logjam of “do we make threads lightweight or not” that currently bedevils industrial runtime system design.

F# async programming can be seen as an implementation of resumptions, and there are many precursors here, for example OCaml delimited continuations, Haskell embeddings of monadic concurrency and papers emphasising the importance of resumptions with regard to concurrency.

You can use F# asynchronous agents on .NET 2.0, 3.5, 4.0, on Linux/Mono/Mac and on Silverlight. Indeed, you can even use F# async programming when F# is translated to Javascript using the WebSharper platform. Enjoy!

关于multithreading - F# 是函数式语言的糟糕选择吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2880682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com