我發現了一些Cloud Haskell演示,我嘗試運行它,但出現錯誤,我不知道爲什麼。錯誤的樣子:Haskell:模式解析錯誤:acc
MasterSlave.hs:18:9:解析錯誤的模式: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'功能嗎? – bheklilr 2015-01-15 16:12:52
另外'remotable ['slave]'看起來應該是'TemplateHaskell',你也打開了嗎? – bheklilr 2015-01-15 16:13:29
我覺得沒有。我怎樣才能設置這個標誌? – nowicode 2015-01-15 16:32:56