Skip to content

Instantly share code, notes, and snippets.

@seanparsons
Created April 22, 2015 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanparsons/32410870fd203bee4466 to your computer and use it in GitHub Desktop.
Save seanparsons/32410870fd203bee4466 to your computer and use it in GitHub Desktop.
Trying to proxy some Thrift calls.
proxyCall :: (Typeable a) => String -> a -> Q Exp
proxyCall serviceName toProxy = do
let parameterCount n a' = case (typeRepArgs a') of
[x, xs] -> if tyConName $ typeRepTyCon x == "IO" then n else parameterCount (n + 1) xs
_ -> undefined
let noOfParameters = parameterCount 0 $ typeOf toProxy
fieldNames <- traverse (\n -> mkName ("a" ++ (show n))) [1..noOfParameters]
valueName <- fmap fromJust $ lookupValueName serviceName
return [p| $(valueName) resource $(fieldNames) = Pool.withResource pool (\(ThriftConnection _ client) -> $(toProxy) client $(fieldNames)) |]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment