Copyright | (c) Serokell, 2016 |
---|---|
License | GPL-3 (see the file LICENSE) |
Maintainer | Serokell <hi@serokell.io> |
Stability | experimental |
Portability | POSIX, GHC |
Safe Haskell | None |
Language | Haskell2010 |
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 #
serverTypeRestriction0 :: Monad m => ServerRestriction m (ServerT m a) Source #
serverTypeRestriction1 :: Monad m => ServerRestriction m (b -> ServerT m a) Source #
serverTypeRestriction2 :: Monad m => ServerRestriction m (c -> b -> ServerT m a) Source #
serverTypeRestriction3 :: Monad m => ServerRestriction m (d -> c -> b -> ServerT m a) 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 #