module Choreography.Network where
import Choreography.Location
import Control.Monad.Freer
import Control.Monad.IO.Class
data NetworkSig m a where
Run :: m a
-> NetworkSig m a
Send :: Show a
=> a
-> LocTm
-> NetworkSig m ()
Recv :: Read a
=> LocTm
-> NetworkSig m a
BCast :: Show a
=> a
-> NetworkSig m ()
type Network m = Freer (NetworkSig m)
run :: m a -> Network m a
run :: forall (m :: * -> *) a. m a -> Network m a
run m a
m = forall (f :: * -> *) a. f a -> Freer f a
toFreer forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. m a -> NetworkSig m a
Run m a
m
send :: Show a => a -> LocTm -> Network m ()
send :: forall a (m :: * -> *). Show a => a -> LocTm -> Network m ()
send a
a LocTm
l = forall (f :: * -> *) a. f a -> Freer f a
toFreer forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *). Show a => a -> LocTm -> NetworkSig m ()
Send a
a LocTm
l
recv :: Read a => LocTm -> Network m a
recv :: forall a (m :: * -> *). Read a => LocTm -> Network m a
recv LocTm
l = forall (f :: * -> *) a. f a -> Freer f a
toFreer forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *). Read a => LocTm -> NetworkSig m a
Recv LocTm
l
broadcast :: Show a => a -> Network m ()
broadcast :: forall a (m :: * -> *). Show a => a -> Network m ()
broadcast a
a = forall (f :: * -> *) a. f a -> Freer f a
toFreer forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *). Show a => a -> NetworkSig m ()
BCast a
a
class Backend c where
runNetwork :: MonadIO m => c -> LocTm -> Network m a -> m a