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 finish and
-- gather the results
执行计划的示意图可以描述为:
do
|
+---------+---------+
| |
a <- Just 1 b <- Just $ Just 2
| |
| c <- b
| |
+---------+---------+
|
return (a, c)
为什么编译器中还没有使用标志或编译指示实现这样的功能?有哪些实际原因?