我在考虑为所谓的
cloud-haskell
Distributed.Process
.. 不管怎么说,我试图摆脱没有人干预的状态
ioref
或
MVars
相反,使用状态转换器并将
Process
单子在底部,像这样:
type ClusterT = StateT ClusterState
type Cluster a = ClusterT Process a
这在使用
Control.Distributed.Process.Lifted
(
https://hackage.haskell.org/package/distributed-process-lifted
mystatefulcomp :: Cluster ()
mystatefulcomp = do
msg <- expect :: Cluster String
old_state <- get
say $ "My old state was " ++ (show old_state)
put $ modifyState curr_state msg
mystatefulcomp
main = do
Right transport <- createTransport '127.0.0.1' '3000' (\n -> ('127.0.0.1', n) defaultTCPParameters
node <- newLocalNode transport initRemoteTable
runProcess node (evalStateT mystatefulcomp initialstate)
where initialstate = ClusterState.empty
这可以很好地工作,允许我很好地构造程序,我可以保持我的状态功能并在
Cluster
单子。
receiveWait
和
match
接收消息。
让我们重写
statefulcomp
接收等待
doSomethingWithString :: String -> Cluster ()
doSomethingWithString str = do
s < get
put $ modifyState s str
mystatefulcomp :: Cluster ()
mystatefulcomp = do
old_state <- get
receiveWait [ match doSomthingWithString ]
new_state <- get
say $ "old state " ++ (show old_state) ++ " new " ++ (show new_state)
自从
(a -> Process b) -> Match b
但我们希望它是一种
(a -> Cluster b) -> Match b
. 这就是我在薄冰上下车的地方。据我所知
控制分布式。过程举起
rexposes公司
Control.Distributed.Process
expect
和
say
火柴
matchIf
我真的为此苦苦挣扎,试图找到一个解决办法或重新实施的方法
火柴
MonadProcess m => (a -> m b) -> Match b
.
任何见解都是必要的。
编辑
因此,在经历了一些烦躁之后,我提出了以下建议
doSomethingWithString :: String -> Cluster ()
doSomethingWithString str = do
s < get
put $ modifyState s str
doSomethingWithInt :: Int -> Cluster ()
...
mystatefulcomp :: Cluster ()
mystatefulcomp = do
old_state <- get
id =<< receiveWait [ match $ return . doSomethingWithString
, match $ return . doSomethingWithInt ]
new_state <- get
say $ "old state " ++ (show old_state) ++ " new " ++ (show new_state)