evanrelf / drama Goto Github PK
View Code? Open in Web Editor NEW๐ญ Actor library for Haskell
Home Page: https://hackage.haskell.org/package/drama
License: BSD 3-Clause "New" or "Revised" License
๐ญ Actor library for Haskell
Home Page: https://hackage.haskell.org/package/drama
License: BSD 3-Clause "New" or "Revised" License
Relevant links:
drama
's use of ki
: #11ki
on Hackage: https://hackage.haskell.org/package/kiki-unlifted
on Hackage: https://hackage.haskell.org/package/ki-unliftedCurrently, the result of the callback passed to receive
is written into an MVar
as-is, for further consumption by another actor/thread.
If this value is not forced to WHNF or NF, this means the thread which performed the call
may spend time/work to evaluate the value, which is counter-intuitive. Furthermore, if an (impure) exception is thrown during said evaluation, this would show up in the receiver, not in the actor that was call
ed (let's not even consider what happens if the callback uses some withFoo
internally and the resulting value depends on said Foo
to still be "open").
Long story short, would it make sense to have a version of receive
(maybe even receive
itself) which evaluates the result of the callback (IMHO to NF by default) before "returning" it to the called?
Unagi's InChan
has an Eq
instance, so I imagine Address
could get (a derived) one as well. This would help keeping Address
es in some list (and removing one of them later).
Since the Actor
monad is basically a ReaderT
, do you think it'd be possible to add instances for exception
's MonadThrow
, MonadCatch
and MonadMask
? Of course, exception handling ought to be handled a bit different in an actor-style architecture, but being able to use bracket
(and similar) to manage resources is quite important nonetheless.
As an example, currently I don't believe it's possible to write an actor which uses network-simple
's listen
and accept
, to then cast
any new client socket to some manager actor.
Currently, receive
's type is (forall res. msg res -> Actor msg res) -> Actor msg ()
. As a result, when using it, a handler for all kinds of messages is passed in, used to process a single message (returning a result of a call
call if needed), and, well, return ()
.
As a result, it's not possible to 'return' values out of a handler into the actor code calling receive
. Hence, a "state" actor, as is provided as an example in the documentation, requires an IORef
(or similar) which gets updated from inside the message handler.
This is, however, quite unlike how this would be done in Erlang, and (IMHO) how it should be done in Haskell. Instead of using an IORef
and some forever $ receive _
, one could use explicit recursion, passing through the state as a pure value.
Hence, I was wondering, could there be a receive' :: (forall res. msg res -> Actor msg (res, a)) -> Actor msg a
, which would allow to implement a "state" actor somewhat like (writing this from memory, please forgive any type/syntax errors):
data StateMessage s a where
Get :: StateMessage s s
Set :: s -> StateMessage s ()
stateKeeper :: s -> Actor (StateMessage s) void
stateKeeper = loop
where
loop s0 = do
s' <- receive $ \case
Get -> (s0, s0)
Set s -> ((), s)
loop s'
drama
, but that violates the actor modelunagi-chan
async
function from unliftio
, and hope adding bracket
s makes it just as safe? Would allow MonadUnliftIO
stuff.isAlive
and kill
/stop
functions (finally
write to some MVar
or something to indicate death? Or takeMVar
to pull the rug out from under a process?)Handler
type from Control.Exception
used for handling different types of exceptions.respond
function that returns a Responded
type, which means the compiler can verify that an actor responds to a message.Responder
type (wrapper around a -> IO ()
).https://hackage.haskell.org/package/open-union: Infix operator for decomp
osing unions, kinda like case union of
or something. Final null case could be made unnecessary by making the operator a type class method.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.