Haskell功能强大且纯粹,所以基本上它具有编译器能够处理隐式并行性所需的所有属性.
考虑这个简单的例子:
f = do
a <- Just 1
b <- Just $ Just 2
-- ^ The above line does not utilize an `a` variable, so it can be safely
-- executed in parallel with the preceding line
c <- b
-- ^ The above line references a `b` variable, so it can only be executed
-- sequentially after it
return (a, c)
-- On the exit from a monad scope we wait for all computations to …Run Code Online (Sandbox Code Playgroud) parallel-processing concurrency haskell compiler-optimization