time-warp-0.1.1.2: Distributed systems execution emulation

Copyright(c) Serokell, 2016
LicenseGPL-3 (see the file LICENSE)
MaintainerSerokell <hi@serokell.io>
Stabilityexperimental
PortabilityPOSIX, GHC
Safe HaskellNone
LanguageHaskell2010

Control.TimeWarp.Rpc.Restriction

Description

This module helps abstragate from concrete instance of MonadRpc.

Consider such example:

sumMethod :: MonadRpc m => Int -> Int -> ServerT m Int
sumMethod a b = return $ a + b

startServer :: MonadRpc m => m ()
startServer = serve 1234 [method "sum" sumMethod]

This code won't compile, because compiler doesn't know that type m in sumMethod is the same m as in startServer, so it can't apply method to sumMethod (MethodType won't be deduced).

Functions restrictServerTypeN, where N is method's arguments number, help to bound the type. They are all defined like return id.

So the error above can be fixed in following way:

startServer :: MonadRpc m => m ()
startServer = do
   idr <- restrictServerType2
   serve 1234 [method "sum" $ idr sumMethod]

Documentation

type ServerRestriction m t = m (t -> t) Source #

serverTypeRestriction4 :: Monad m => ServerRestriction m (e -> d -> c -> b -> ServerT m a) Source #

serverTypeRestriction5 :: Monad m => ServerRestriction m (f -> e -> d -> c -> b -> ServerT m a) Source #