54 karma · joined November 5, 2014
transient-universe can run Browser nodes compiled from haskell to Javascript. they can display DOM widgets and are integrated with server nodes, using websockets communications. Just compile the program with the Haskelll to JS compiler and point the browser to http://server:port. The server nodes have a HTTP server that will send the compiled program to the browser.
Haxl uses a controlling thread that spawn worker threads and is single purpose. No distributed computing in the strong sense.
transient has no controlling thread. It run multiple threads and is general purpose.
The alternative operator <|> can spawn parallel threads/or parallel distributed computations that follow the flow of the monad. for example:
r <- runAt node1 foo <|> runAt node2 bar
lliftIO $ print r
will print two results, since there are two thread generated. Well there may be any number of results because any of the two branches may generate multiple threads or none, since they can stop without any result.(if we need a single thread, we can use `collect`)
note that `foo` and `bar` are distributed programs as well, so they can invoke other nodes and so on.
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.
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 pingPong receiver=
wormhole receiver $ do
teleport
lliftIO $ print "ping"
teleport
lliftIO $ print "pong"
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:
streamFrom node=
wormhole node $ do
teleport
r <- threads 1 $ choose[1..]
threadDelay 1000000
teleport
return r
I can compose both distributed programs: composed node = do
r <- (pingPong node >> return 0) <|> streamFrom node
lliftIO $ case r of
0 -> putStrLn "pong was received"
n -> print n
`composed` print the numbers received and the "pong" messages followed by "pong was received" in the console of the caller.This backtracking is different since it permits different backtracking points. It is possible to implement a more "civilized" version of the STM semantics this way, with more respect for IO actions.
ideographic writing is more complex and less composable than phonetic writing and yet can express the same ideas.
Subjectively, a chinese can understand Chinese ideograms while maybe he find written English difficult to understand. But a Chinese would learn phonetic writing in less time than ideographic writing and would be capable to express complex ideas using the most composable writing system in less time, no doubt.
This is just random thoughts and there is much more to say. Neither I pretend to tell that OOP is wrong. What I say in the article is that the deconstruction of the recipe that OOP naturally demand is very painful and has too many drawbacks, and can be avoided with the right tools.
In the case of events, it is because I later have to store different event types in a List
so I define the list as [Event] . That is the container that feed the monad with events.
If I define Event as you suggest, I would need a existential type anyway.
data Event a = Event EvType a
data ListEvents= forall a.[Event a]
In the case of the continuations, I need to use a state monad that store this EventF data And I need to "erase" in some way the types to allow it to store them all for all events, no matter wich a and b they produce. I know that if in x :: IO a
f :: a -> m b
If within the monad definition I store f (the rest of the computation) in the state monad, the type of this continuation when executed will be (m b) and it accept values of type `a` so I can coerce the continuation to this type even if I "erased" it when i put it in the state monad.Anyway this approach has some problems that I solved in the second part