【发布时间】:2015-03-14 02:19:10
【问题描述】:
我找到了一些 Cloud Haskell Demos 并尝试运行它,但我得到一个错误,我不知道为什么。错误看起来像:
MasterSlave.hs:18:9:pattern:acc 中的解析错误
MasterSlave.hs 中的代码是:
module MasterSlave where
import Control.Monad
import Control.Distributed.Process
import Control.Distributed.Process.Closure
import PrimeFactors
slave :: (ProcessId, Integer) -> Process ()
slave (pid, n) = send pid (numPrimeFactors n)
remotable ['slave]
-- | Wait for n integers and sum them all up
sumIntegers :: Int -> Process Integer
sumIntegers = go 0
where
go :: Integer -> Int -> Process Integer
go !acc 0 = return acc
go !acc n = do
m <- expect
go (acc + m) (n - 1)
data SpawnStrategy = SpawnSyncWithReconnect
| SpawnSyncNoReconnect
| SpawnAsync
deriving (Show, Read)
master :: Integer -> SpawnStrategy -> [NodeId] -> Process Integer
master n spawnStrategy slaves = do
us <- getSelfPid
-- Distribute 1 .. n amongst the slave processes
spawnLocal $ case spawnStrategy of
SpawnSyncWithReconnect ->
forM_ (zip [1 .. n] (cycle slaves)) $ \(m, there) -> do
them <- spawn there ($(mkClosure 'slave) (us, m))
reconnect them
SpawnSyncNoReconnect ->
forM_ (zip [1 .. n] (cycle slaves)) $ \(m, there) -> do
_them <- spawn there ($(mkClosure 'slave) (us, m))
return ()
SpawnAsync ->
forM_ (zip [1 .. n] (cycle slaves)) $ \(m, there) -> do
spawnAsync there ($(mkClosure 'slave) (us, m))
_ <- expectTimeout 0 :: Process (Maybe DidSpawn)
return ()
-- Wait for the result
sumIntegers (fromIntegral n)
这段代码有什么问题?
【问题讨论】:
-
您是否启用了
BangPatterns? -
另外
remotable ['slave]看起来应该是TemplateHaskell,你也打开了吗? -
我认为没有。如何设置此标志?
-
将
{-# LANGUAGE ExtensionName #-}放在源文件的顶部(在模块声明之前),用于您要启用的每个扩展。 -
非常感谢!这就是问题所在。
标签: haskell parse-error