nano-erl-0.1.0.1: Small library for Erlang-style actor semantics

Safe HaskellNone
LanguageHaskell2010
ExtensionsLambdaCase

Control.Concurrent.NanoErl

Description

A small library for Erlang-style actor semantics, for coordinating concurrent processes and message passing

Synopsis

Documentation

type Process message = Pid message -> IO () Source

A process takes its own Pid, to receive messages with, and can do any IO actions

spawn :: Process message -> IO (Pid message) Source

Start up a concurrent process and get a reference to it

data Pid message Source

Process ID: the way we refer to concurrent processes. Send messages to them with !

Instances

Eq (Pid message) Source 
Ord (Pid message) Source 
Show (Pid message) Source 

(!) :: Pid message -> message -> IO () Source

Send a message to another process's "mailbox." The messages are handled with receive

Like Erlang, we ignore any messages sent to processes that have died

receive :: Pid message -> (message -> IO a) -> IO a Source

Receive data from the process's "mailbox"

If there are no messages in the mailbox, the process waits until there is one then handles it

Note at the moment we don't enforce in the type system that a process is only reading its own mailbox, but that's the idiom in Erlang (1 mailbox per process)

runNanoErl :: IO a -> IO a Source

Put this at the toplevel of your program, e.g.

main = runNanoErl $ ...

To ensure that your program doesn't exit before all its spawned processes have finished running

kill :: Pid message -> IO () Source

Kill a process