1 # transport: an effect service: one message body in, one out. H is the 2 # implementation's handle state; it is affine, so every call hands it back. 3 import Base 4 5 # effect service over a handle H: receive a body, send a body, each handing the 6 # handle back 7 type Transport<-H: Type> is Type: # noqa: L001 effect record 8 Transport{recv: H -> IO(H & Maybe<&2, String>), send: H -> String -> IO(H)} 9 10 # the next message's body; None when the peer is gone 11 def recv(-H: Type, tt: Transport, hh: H) -> IO(H & Maybe<&2, String>): # noqa: L001 effect accessor 12 Transport{r, s} = tt 13 r(hh) 14 15 # a body, through a transport 16 def send(-H: Type, tt: Transport, hh: H, body: String) -> IO(H): # noqa: L001 effect accessor 17 Transport{r, s} = tt 18 s(hh, body)