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.
14data Process : (msgType : Type) -> Type -> Type where
15 Lift : IO a -> Process msg a
17instance Functor (Process msg) where
18 map f (Lift a) = Lift (map f a)
20instance Applicative (Process msg) where
22 (Lift f) <$> (Lift a) = Lift (f <$> a)
24instance Monad (Process msg) where
25 (Lift io) >>= k = Lift (do x <- io
29run : Process msg x -> IO x
32||| Get current process ID
33myID : Process msg (ProcID msg)
34myID = Lift (return (MkPID prim__vm))
36||| Send a message to another process
37send : ProcID msg -> msg -> Process msg ()
38send (MkPID p) m = Lift (sendToThread p (prim__vm, m))
40||| Return whether a message is waiting in the queue
41msgWaiting : Process msg Bool
42msgWaiting = Lift checkMsgs
44||| Receive a message - blocks if there is no message waiting
46recv {msg} = do (senderid, m) <- Lift get
48 where get : IO (Ptr, msg)
51||| receive a message, and return with the sender's process ID.
52recvWithSender : Process msg (ProcID msg, msg)
54 = do (senderid, m) <- Lift get
55 return (MkPID senderid, m)
56 where get : IO (Ptr, msg)
59create : Process msg () -> Process msg (ProcID msg)
60create (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