{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Network.TypedProtocol.Stateful.ReqResp.Examples where
import Network.TypedProtocol.Stateful.ReqResp.Server
import Network.TypedProtocol.Stateful.ReqResp.Type
fileRPCServer :: Monad m
=> (forall resp. FileAPI resp -> m resp)
-> ReqRespServer FileAPI m ()
fileRPCServer :: forall (m :: * -> *).
Monad m =>
(forall resp. FileAPI resp -> m resp) -> ReqRespServer FileAPI m ()
fileRPCServer forall resp. FileAPI resp -> m resp
run = ReqRespServer {
reqRespServerDone :: ()
reqRespServerDone = (),
reqRespHandleReq :: forall resp.
Typeable resp =>
FileAPI resp -> m (resp, ReqRespServer FileAPI m ())
reqRespHandleReq = \FileAPI resp
req -> do
resp <- FileAPI resp -> m resp
forall resp. FileAPI resp -> m resp
run FileAPI resp
req
return (resp, fileRPCServer run)
}
simpleFileAPI :: Monad m => FileAPI resp -> m resp
simpleFileAPI :: forall (m :: * -> *) resp. Monad m => FileAPI resp -> m resp
simpleFileAPI (ReadFile [Char]
filepath) = resp -> m resp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return resp
[Char]
filepath
simpleFileAPI (WriteFile [Char]
_ [Char]
_) = resp -> m resp
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
simpleFileRPCServer :: Monad m => ReqRespServer FileAPI m ()
simpleFileRPCServer :: forall (m :: * -> *). Monad m => ReqRespServer FileAPI m ()
simpleFileRPCServer = (forall resp. FileAPI resp -> m resp) -> ReqRespServer FileAPI m ()
forall (m :: * -> *).
Monad m =>
(forall resp. FileAPI resp -> m resp) -> ReqRespServer FileAPI m ()
fileRPCServer FileAPI resp -> m resp
forall resp. FileAPI resp -> m resp
forall (m :: * -> *) resp. Monad m => FileAPI resp -> m resp
simpleFileAPI