Haskell – parallel strategy using Monad

I often see the use and interpretation of Haskell's parallel strategy related to pure computing (such as FIB) However, I don't often see it used with monadic structure: when applied to st or IO, is there a reasonable explanation for the effect of PAR and related functions? Will such use increase any acceleration?

Solution

Parallelism in io monad is more accurately called "concurrency" and is controlled by control Forkio and friend support in concurrent module

The difficulty of parallelizing st monad is that st must be single threaded - that's its purpose St monad has a lazy variant, control Monad. St. lazy, it can support parallel evaluation in principle, but I don't know anyone trying to do so

There is a new monad for parallel evaluation, called Eval, which can be found in the latest version of parallel package I recommend Eval monad with rPar and rseq instead of PAR and PSEQ, because it will lead to more powerful and readable code For example, you can write a typical FIB example

fib n = if n < 2 then 1 else 
        runEval $do
           x <- rpar (fib (n-1))
           y <- rseq (fib (n-2))
           return (x+y)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>