4 | module Data.Linear.Communications
7 | import Data.Linear.Inverse
15 | data Protocol : Type where
16 | Send : Type -> Protocol -> Protocol
17 | Recv : Type -> Protocol -> Protocol
21 | Dual : Protocol -> Protocol
22 | Dual (Send x s) = Recv x (Dual s)
23 | Dual (Recv x s) = Send x (Dual s)
27 | data LChan : Protocol -> Type where
32 | (send : forall s, a. LChan (Send a s) -@ a -@ LChan s)
33 | (recv : forall s, a. LChan (Recv a s) -@ LPair a (LChan s))
34 | (close : LChan End -@ ())
36 | (fork : (0 s : Protocol) -> Inverse (LChan s) -@ LChan (Dual s))
39 | involOp : Inverse (Inverse a) -@ a
43 | 1 r : LChan (Dual P)
44 | := fork P $
mkInverse $
\ s =>
45 | (`divide` k) $
mkInverse $
46 | \ x => let 1 c = send s x in close c