simple-actors-0.0.1: A simple implementation of the actor model of concurrency




Actor computations

type Actor i = i -> ActorM (NextActor i)Source

type Loop = ActorM (NextActor ())Source

An Actor that discards its input, i.e. a simple loop.

newtype NextActor i Source




nextActor :: Actor i

data ActorM a Source

The Actor encironment in which Actors can be spawned and sent messages

Building Actors

continue :: Actor i -> ActorM (NextActor i)Source

Continue with a new Actor computation step

continue_ :: Loop -> ActorM (NextActor i)Source

Continue with a Loop computation

done :: ActorM (NextActor i)Source

Actor terminating:

aseq :: Actor i -> Actor i -> Actor iSource

compose two actors. The second will take over when the first exits

Message passing and IO

send :: Action m => Mailbox a -> a -> m ()Source

Send a message to an Actor. Actors can only be passed messages from other actors.

Actor system output:

receive :: Mailbox o -> IO oSource

Read a message from a mailbox in the IO monad. This can be used as the mechanism for output from an Actor system. Blocks if the actor is empty

receiveList :: Mailbox o -> IO [o]Source

Return a lazy list of mailbox contents


data Mailbox i Source

the buffered message passing medium used between actors

newMailbox :: Action m => m (Mailbox a)Source

create a new mailbox that Actors can be launched to read from or send messages to in order to communicate with other actors

Running Actors

class Monad m => Action m Source

monads in the Action class can participate in message passing and other Actor operations


forkActor :: Action m => Actor i -> m (Mailbox i)Source

fork an actor, returning its mailbox

forkActorUsing :: Action m => Mailbox i -> Actor i -> m ()Source

fork an actor that reads from the supplied Mailbox

forkLoop :: Action m => Loop -> m ()Source

fork a looping computation which starts immediately

runActorUsing :: Mailbox i -> Actor i -> IO ()Source

run an Actor in the main thread, returning when the Actor exits

runLoop :: Loop -> IO ()Source

run a Loop actor in the main thread, returning when the computation exits