-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Small library for Erlang-style actor semantics
--   
--   A small, beginner-friendly library for Erlang-style actor semantics,
--   for coordinating concurrent processes and message passing
--   
--   Processes are plain IO actions, so no monad transformers needed (no
--   liftIO!)
--   
--   For best performance, compile with:
--   
--   <pre>
--   ghc -O2 -threaded -rtsopts -with-rtsopts=-N
--   </pre>
@package nano-erl
@version 0.1.0.1


-- | A small library for Erlang-style actor semantics, for coordinating
--   concurrent processes and message passing
module Control.Concurrent.NanoErl

-- | A process takes its own <a>Pid</a>, to receive messages with, and can
--   do any IO actions
type Process message = Pid message -> IO ()

-- | Start up a concurrent process and get a reference to it
spawn :: Process message -> IO (Pid message)

-- | Process ID: the way we refer to concurrent processes. Send messages to
--   them with <a>!</a>
data Pid message

-- | Send a message to another process's "mailbox." The messages are
--   handled with <a>receive</a>
--   
--   Like Erlang, we ignore any messages sent to processes that have died
(!) :: Pid message -> message -> IO ()

-- | 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)
receive :: Pid message -> (message -> IO a) -> IO a

-- | Put this at the toplevel of your program, e.g.
--   
--   <pre>
--   main = runNanoErl $ ...
--   </pre>
--   
--   To ensure that your program doesn't exit before all its <a>spawn</a>ed
--   processes have finished running
runNanoErl :: IO a -> IO a

-- | Kill a process
kill :: Pid message -> IO ()
instance GHC.Classes.Eq (Control.Concurrent.NanoErl.Pid message)
instance GHC.Show.Show (Control.Concurrent.NanoErl.Pid message)
instance GHC.Classes.Ord (Control.Concurrent.NanoErl.Pid message)


-- | Makes a "line of dominos" of processes which each wait for a
--   <a>Fall</a> message, then terminate. The dominos are in a "circle" so
--   they're all created before any terminate
module Control.Concurrent.NanoErl.Examples.Dominos
data Fall
Fall :: Fall
numDominos :: Int
main :: IO ()
makeDominos :: Int -> Maybe (Pid Fall) -> Process Fall
instance GHC.Show.Show Control.Concurrent.NanoErl.Examples.Dominos.Fall


-- | Create two processes which bounce "Ping" and "Pong" messages back and
--   forth to each other
module Control.Concurrent.NanoErl.Examples.PingPong
main :: IO ()
data PingPongMsg
Ping :: (Pid PingPongMsg) -> PingPongMsg
Pong :: (Pid PingPongMsg) -> PingPongMsg
pingPong :: Process PingPongMsg
instance GHC.Show.Show Control.Concurrent.NanoErl.Examples.PingPong.PingPongMsg
