Taking away the initializations, this is the ping pong example in Erlang:
https://gist.github.com/torgeir/3978785
ping(Receiver) -> { pong, Receiver } ! { ping, self() }, receive pong -> io:format("Got pong!~n") end. pong() -> receive finished -> io:format("Pong finished~n"); { ping, Sender } -> io:format("Got ping!~n"), Sender ! pong, pong() end.
pingPong receiver= wormhole receiver $ do teleport lliftIO $ print "ping" teleport lliftIO $ print "pong"
Just start the program in both nodes (initialization code is not shown)
This is a distributed program but I can compose this program with any other.
This other program stream integers from a remote node from 1 in increasing order:
streamFrom node= wormhole node $ do teleport r <- threads 1 $ choose[1..] threadDelay 1000000 teleport return r
composed node = do r <- (pingPong node >> return 0) <|> streamFrom node lliftIO $ case r of 0 -> putStrLn "pong was received" n -> print n
Taking away the initializations, this is the ping pong example in Erlang:
https://gist.github.com/torgeir/3978785
This is the same in Transient: A message is sent to the receiver print "ping" in his console, then send a message to the sender, that print "pong" in his console You see that the ping and the pong are composed "monadically" in a single piece of code. The flow is quite understandable.Just start the program in both nodes (initialization code is not shown)
This is a distributed program but I can compose this program with any other.
This other program stream integers from a remote node from 1 in increasing order:
I can compose both distributed programs: `composed` print the numbers received and the "pong" messages followed by "pong was received" in the console of the caller.