polysemy-research / polysemy-zoo

:monkey::panda_face: Experimental, user-contributed effects and interpreters for polysemy
BSD 3-Clause "New" or "Revised" License
70 stars 20 forks source link

RPC effect #4

Open isovector opened 5 years ago

isovector commented 5 years ago

Consider this:

We can automatically provide RPC stubs for any first-order effect, and for any second-order effect that is called with StaticPtrs.

How?

data RPC c m a where
  DoRPC :: c -> RPC c m c

where c is some type for marshalling, maybe a Data.JSON.Value or a ByteString or something.

We can then transform effects into RPC calls:

runAsRPC :: (ToRPC e c, Member (RPC c) r) => Sem (e ': r) a -> Sem r a
runAsRPC = interpret $ fmap fromRPC . doRPC . toRPC

where the marshalling details come generically from the ToRPC instance, possibly built around the one-liner machinery.

This lets you send RPC calls; to respond to them you can do something with an RPC handler that receives RPC messages and then uses intercept to respond to them. I haven't hashed out the details of this bit yet, but it seems super doable.

isovector commented 5 years ago

https://github.com/isovector/polysemy/pull/83