From a4bb467446da707b6191d83e19fed2d608493434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Hahn?= Date: Sun, 23 Oct 2016 23:48:36 -0400 Subject: [PATCH] remove 'forall's from haddock docs --- .../Servant/Server/Utils/CustomCombinators.hs | 91 +++++++++++++------ .../Server/Utils/CustomCombinatorsSpec.hs | 2 - 2 files changed, 64 insertions(+), 29 deletions(-) diff --git a/servant-server/src/Servant/Server/Utils/CustomCombinators.hs b/servant-server/src/Servant/Server/Utils/CustomCombinators.hs index dcbd2d94..4d3c6926 100644 --- a/servant-server/src/Servant/Server/Utils/CustomCombinators.hs +++ b/servant-server/src/Servant/Server/Utils/CustomCombinators.hs @@ -55,63 +55,100 @@ runCI :: CombinatorImplementation combinator arg api context runCI (CI i) = i makeCaptureCombinator :: - forall api combinator arg context . (HasServer api context, WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler)) => (Context context -> Text -> IO (RouteResult arg)) -> CombinatorImplementation combinator arg api context -makeCaptureCombinator getArg = CI $ \ Proxy context delayed -> - CaptureRouter $ - route (Proxy :: Proxy api) context $ addCapture delayed $ \ captured -> - (liftRouteResult =<< liftIO (getArg context captured)) +makeCaptureCombinator = inner -- we use 'inner' to avoid having 'forall' show up in haddock docs + where + inner :: + forall api combinator arg context . + (HasServer api context, + WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler)) => + (Context context -> Text -> IO (RouteResult arg)) + -> CombinatorImplementation combinator arg api context + inner getArg = CI $ \ Proxy context delayed -> + CaptureRouter $ + route (Proxy :: Proxy api) context $ addCapture delayed $ \ captured -> + (liftRouteResult =<< liftIO (getArg context captured)) makeRequestCheckCombinator :: - forall api combinator context . (HasServer api context, WithArg () (ServerT api Handler) ~ ServerT api Handler) => (Context context -> Request -> IO (RouteResult ())) -> CombinatorImplementation combinator () api context -makeRequestCheckCombinator check = CI $ \ Proxy context delayed -> - route (Proxy :: Proxy api) context $ addMethodCheck delayed $ - withRequest $ \ request -> - liftRouteResult =<< liftIO (check context (protectBody "makeRequestCheckCombinator" request)) +makeRequestCheckCombinator = inner + where + inner :: + forall api combinator context . + (HasServer api context, + WithArg () (ServerT api Handler) ~ ServerT api Handler) => + (Context context -> Request -> IO (RouteResult ())) + -> CombinatorImplementation combinator () api context + inner check = CI $ \ Proxy context delayed -> + route (Proxy :: Proxy api) context $ addMethodCheck delayed $ + withRequest $ \ request -> + liftRouteResult =<< liftIO (check context (protectBody "makeRequestCheckCombinator" request)) makeAuthCombinator :: - forall api combinator arg context . (HasServer api context, WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler)) => (Context context -> Request -> IO (RouteResult arg)) -> CombinatorImplementation combinator arg api context -makeAuthCombinator authCheck = CI $ \ Proxy context delayed -> - route (Proxy :: Proxy api) context $ addAuthCheck delayed $ - withRequest $ \ request -> - liftRouteResult =<< liftIO (authCheck context (protectBody "makeAuthCombinator" request)) +makeAuthCombinator = inner + where + inner :: + forall api combinator arg context . + (HasServer api context, + WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler)) => + (Context context -> Request -> IO (RouteResult arg)) + -> CombinatorImplementation combinator arg api context + inner authCheck = CI $ \ Proxy context delayed -> + route (Proxy :: Proxy api) context $ addAuthCheck delayed $ + withRequest $ \ request -> + liftRouteResult =<< liftIO (authCheck context (protectBody "makeAuthCombinator" request)) makeReqBodyCombinator :: - forall api combinator arg context . (ServerT (combinator :> api) Handler ~ (arg -> ServerT api Handler), WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler), HasServer api context) => (Context context -> IO ByteString -> arg) -> CombinatorImplementation combinator arg api context -makeReqBodyCombinator getArg = CI $ \ Proxy context delayed -> - route (Proxy :: Proxy api) context $ addBodyCheck delayed - (return ()) - (\ () -> withRequest $ \ request -> - liftRouteResult $ Route $ getArg context $ requestBody request) +makeReqBodyCombinator = inner + where + inner :: + forall api combinator arg context . + (ServerT (combinator :> api) Handler ~ (arg -> ServerT api Handler), + WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler), + HasServer api context) => + (Context context -> IO ByteString -> arg) + -> CombinatorImplementation combinator arg api context + inner getArg = CI $ \ Proxy context delayed -> + route (Proxy :: Proxy api) context $ addBodyCheck delayed + (return ()) + (\ () -> withRequest $ \ request -> + liftRouteResult $ Route $ getArg context $ requestBody request) makeCombinator :: - forall api combinator arg context . (ServerT (combinator :> api) Handler ~ (arg -> ServerT api Handler), WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler), HasServer api context) => (Context context -> Request -> IO (RouteResult arg)) -> CombinatorImplementation combinator arg api context -makeCombinator getArg = CI $ \ Proxy context delayed -> - route (Proxy :: Proxy api) context $ addBodyCheck delayed - (return ()) - (\ () -> withRequest $ \ request -> - liftRouteResult =<< liftIO (getArg context (protectBody "makeCombinator" request))) +makeCombinator = inner + where + inner :: + forall api combinator arg context . + (ServerT (combinator :> api) Handler ~ (arg -> ServerT api Handler), + WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler), + HasServer api context) => + (Context context -> Request -> IO (RouteResult arg)) + -> CombinatorImplementation combinator arg api context + inner getArg = CI $ \ Proxy context delayed -> + route (Proxy :: Proxy api) context $ addBodyCheck delayed + (return ()) + (\ () -> withRequest $ \ request -> + liftRouteResult =<< liftIO (getArg context (protectBody "makeCombinator" request))) protectBody :: String -> Request -> Request protectBody name request = request{ diff --git a/servant-server/test/Servant/Server/Utils/CustomCombinatorsSpec.hs b/servant-server/test/Servant/Server/Utils/CustomCombinatorsSpec.hs index a1d62a1e..08a91e0b 100644 --- a/servant-server/test/Servant/Server/Utils/CustomCombinatorsSpec.hs +++ b/servant-server/test/Servant/Server/Utils/CustomCombinatorsSpec.hs @@ -255,8 +255,6 @@ instance (HasContextEntry context [(SBS.ByteString, User)], HasServer api contex type ServerT (AuthWithContext :> api) m = User -> ServerT api m route = runCI $ makeAuthCombinator authWithContext --- fixme: remove foralls from haddock - authWithContext :: (HasContextEntry context [(SBS.ByteString, User)]) => Context context -> Request -> IO (RouteResult User) authWithContext context request = return $ case lookup "Auth" (requestHeaders request) of