It seems that TH uses types somewhat ambiguously (at least between
versions) and the patch series fails to compile in my squeeze schroot,
because 'varName' doesn't match on a tuple.
Adding this case to 'varName' fixes the problem:
varName idx (AppT (AppT (TupleT 2) t) t')
= pairOf idx t t'
(I observed the issue in the past, this is why all the cases have two
variants.)
Otherwise LGTM, no need to resend.
On Mon, Mar 3, 2014 at 2:48 PM, Klaus Aehlig <[email protected]> wrote:
> Add support for naming of python variables if the type
> is a pair.
>
> Note: on older versions of haskell, Q is not an instance of
> Applicative, hence we use the do-syntax here.
>
> Signed-off-by: Klaus Aehlig <[email protected]>
> ---
> src/Ganeti/THH/PyRPC.hs | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/src/Ganeti/THH/PyRPC.hs b/src/Ganeti/THH/PyRPC.hs
> index dd7c6b7..a607c53 100644
> --- a/src/Ganeti/THH/PyRPC.hs
> +++ b/src/Ganeti/THH/PyRPC.hs
> @@ -98,6 +98,8 @@ toFunc fname as = do
> varName idx (AppT ListT t) = listOf idx t
> varName idx (AppT (ConT n) t)
> | n == ''[] = listOf idx t
> + varName idx (AppT (AppT (ConT n) t) t')
> + | n == ''(,) = pairOf idx t t'
> varName idx t = do
> report False $ "Don't know how to make a Python variable name from "
> ++ show t ++ "; using a numbered one."
> @@ -108,6 +110,14 @@ toFunc fname as = do
> listOf :: Int -> Type -> Q Doc
> listOf idx t = (<> text "List") <$> varName idx t
>
> + -- | Create a name for a method argument, knowing that its a pair of
> + -- the given types.
> + pairOf :: Int -> Type -> Type -> Q Doc
> + pairOf idx t t' = do
> + tn <- varName idx t
> + tn' <- varName idx t'
> + return $ tn <> text "_" <> tn' <> text "_Pair"
> +
> lowerFirstNameQ :: Name -> Q Doc
> lowerFirstNameQ = return . text . lowerFirst . nameBase
>
> --
> 1.9.0.279.gdc9e3eb
>
>