Does F# provide you automatic parallelism?

后端 未结 8 2056
栀梦
栀梦 2020-12-28 17:25

By this I meant: when you design your app side effects free, etc, will F# code be automatically distributed across all cores?

相关标签:
8条回答
  • 2020-12-28 18:07

    No, I'm pretty sure that it won't automatically parallelise for you. It would have to know that your code was side-effect free, which could be hard to prove, for one thing.

    Of course, F# can make it easier to parallelise your code, particularly if you don't have any side effects... but that's a different matter.

    0 讨论(0)
  • 2020-12-28 18:12

    No, I'm afraid not. Given that F# isn't a pure functional language (in the strictest sense), it would be rather difficult to do so I believe. The primary way to make good use of parallelism in F# is to use Async Workflows (mainly via the Async module I believe). The TPL (Task Parallel Library), which is being introduced with .NET 4.0, is going to fulfil a similar role in F# (though notably it can be used in all .NET languages equally well), though I can't say I'm sure exactly how it's going to integrate with the existing async framework. Perhaps Microsoft will simply advise the use of the TPL for everything, or maybe they will leave both as an option and one will eventually become the de facto standard...

    Anyway, here are a few articles on asynchronous programming/workflows in F# to get you started.

    • http://blogs.msdn.com/dsyme/archive/2007/10/11/introducing-f-asynchronous-workflows.aspx
    • http://strangelights.com/blog/archive/2007/09/29/1597.aspx
    • http://www.infoq.com/articles/pickering-fsharp-async
    0 讨论(0)
提交回复
热议问题