Concurrent with monads

Hi cafe, I wounder if it is possible to tell a haskell system that two computations with side effects could be executed concurrently. Here is an affected example: Suppose two people want to compare their age, but do not want to leak their personal information. The following program reads one person's age after another then send back compared result. age :: IO () age = do i <- readIntFrom a j <- readIntFrom b writeTo a (i-j) writeTo b (j-i) How can I express the fact that two readings could be carried out in any order? Best Regards Jiansen

On 10-11-14 07:36 PM, Jiansen He wrote:
Hi cafe,
I wounder if it is possible to tell a haskell system that two computations with side effects could be executed concurrently.
Here is an affected example:
Suppose two people want to compare their age, but do not want to leak their personal information. The following program reads one person's age after another then send back compared result.
age :: IO () age = do i <- readIntFrom a j <- readIntFrom b writeTo a (i-j) writeTo b (j-i)
How can I express the fact that two readings could be carried out in any order?
You can use the monad-parallel package. Your example could be written as
import qualified Monad.Parallel as MP
age :: IO () age = do (i, j) <- MP.liftM2 (,) (readIntFrom a) (readIntFrom b) writeTo a (i-j) writeTo b (j-i)
participants (2)
-
Jiansen He
-
Mario Blažević