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