1-- WARNING: No guarantees that this works properly yet!
3module System.Concurrency.Process
5import System.Concurrency.Raw
10data ProcID msg = MkPID Ptr
12-- Type safe message passing programs. Parameterised over the type of
13-- message which can be send, and the return type.
15data Process : (msgType : Type) -> Type -> Type where
16 lift : IO a -> Process msg a
18instance Functor (Process msg) where
19 map f (lift a) = lift (map f a)
21instance Applicative (Process msg) where
23 (lift f) <$> (lift a) = lift (f <$> a)
25instance Monad (Process msg) where
26 (lift io) >>= k = lift (do x <- io
30run : Process msg x -> IO x
33-- Get current process ID
35myID : Process msg (ProcID msg)
36myID = lift (return (MkPID prim__vm))
38-- Send a message to another process
40send : ProcID msg -> msg -> Process msg ()
41send (MkPID p) m = lift (sendToThread p (prim__vm, m))
43-- Return whether a message is waiting in the queue
45msgWaiting : Process msg Bool
46msgWaiting = lift checkMsgs
48-- Receive a message - blocks if there is no message waiting
51recv {msg} = do (senderid, m) <- lift get
53 where get : IO (Ptr, msg)
56-- receive a message, and return with the sender's process ID.
58recvWithSender : Process msg (ProcID msg, msg)
60 = do (senderid, m) <- lift get
61 return (MkPID senderid, m)
62 where get : IO (Ptr, msg)
65create : |(thread : Process msg ()) -> Process msg (ProcID msg)
66create (lift p) = do ptr <- lift (fork p)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list