I have a hard time to grasp cond. I finally managed to get this snippet to work https://gist.github.com/justjoheinz/b764c28ad4be3aa317a0780a178cf18f
however when running it, it prints errors to the console (more later)
The intention is to have Alice, Bob and Carol. Alice makes a decision who still needs to work and the other can go home:
subChoreography :: Bool -> Choreo Worker IO ()
-- see gist for implementation
choreography :: Choreo Participants IO ()
choreography = do
let allParticipants = allOf @Participants
alice `_locally_` putStrLn "Alice: Please enter who needs to work (bob | alice):"
decision :: Located '["alice"] Bool <- alice `_locally` fmap (== "bob") getLine
sharedDecision :: Located Participants Bool <- (alice, decision) ~> allParticipants
_ <- (worker, (worker, sharedDecision)) `cond` subChoreography
pure ()
When running three instances Alice will output
Alice: Please enter who needs to work (bob | alice):
bob
alice-bob-carol-4-exe: Data.HashMap.Internal.(!): key not found
CallStack (from HasCallStack):
error, called at ./Data/HashMap/Internal.hs:774:16 in unordered-containers-0.2.20-FdjUkqnun0861bQxdLMMwI:Data.HashMap.Internal
!, called at src/Choreography/Network/Http.hs:92:93 in MultiChor-1.1.0.0-68YA4fWAe5SK4s8tA1pBpM:Choreography.Network.Http
This error happens with all backends (http, local).
Using a conclave I am able to express my intent better (almost the same algorithm):
subChoreography :: Located Worker Bool -> Choreo Worker IO ()
subChoreography sharedDecision = do
b <- naked (refl @Worker) sharedDecision
-- ... same as above
makeDecision :: IO Bool
makeDecision = do
putStrLn "Please enter who needs to work:"
decision <- getLine
return (decision == "bob")
choreography :: Choreo Participants IO ()
choreography = do
sharedDecision <- (alice, makeDecision) -~> worker
_ <- conclave worker (subChoreography sharedDecision)
return ()
I have problems to
- grasp the signature of cond and how to apply it to my problem that the knowledge of the decision should actually be on with workers and not allparticipants?
- decide whether the error above is my error or a bug in MultiChor.
I have a hard time to grasp
cond. I finally managed to get this snippet to work https://gist.github.com/justjoheinz/b764c28ad4be3aa317a0780a178cf18fhowever when running it, it prints errors to the console (more later)
The intention is to have Alice, Bob and Carol. Alice makes a decision who still needs to work and the other can go home:
When running three instances Alice will output
This error happens with all backends (http, local).
Using a conclave I am able to express my intent better (almost the same algorithm):
I have problems to