LGTM, thanks.

On Mon, Oct 7, 2013 at 4:37 PM, Jose A. Lopes <[email protected]> wrote:

> Add 'declareILADT' to declare integer literal datatypes.
>
> Signed-off-by: Jose A. Lopes <[email protected]>
> ---
>  src/Ganeti/THH.hs | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/src/Ganeti/THH.hs b/src/Ganeti/THH.hs
> index 7865e6f..4d8417b 100644
> --- a/src/Ganeti/THH.hs
> +++ b/src/Ganeti/THH.hs
> @@ -1,4 +1,4 @@
> -{-# LANGUAGE ExistentialQuantification, TemplateHaskell #-}
> +{-# LANGUAGE ExistentialQuantification, ParallelListComp, TemplateHaskell
> #-}
>
>  {-| TemplateHaskell helper for Ganeti Haskell code.
>
> @@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor,
> Boston, MA
>
>  module Ganeti.THH ( declareSADT
>                    , declareLADT
> +                  , declareILADT
>                    , declareIADT
>                    , makeJSONInstance
>                    , deCamelCase
> @@ -414,6 +415,19 @@ declareADT fn traw sname cons = do
>  declareLADT :: Name -> String -> [(String, String)] -> Q [Dec]
>  declareLADT = declareADT Left
>
> +declareILADT :: String -> [(String, Int)] -> Q [Dec]
> +declareILADT sname cons = do
> +  consNames <- sequence [ newName ('_':n) | (n, _) <- cons ]
> +  consFns <- concat <$> sequence
> +             [ do sig <- sigD n [t| Int |]
> +                  let expr = litE (IntegerL (toInteger i))
> +                  fn <- funD n [clause [] (normalB expr) []]
> +                  return [sig, fn]
> +             | n <- consNames
> +             | (_, i) <- cons ]
> +  let cons' = [ (n, n') | (n, _) <- cons | n' <- consNames ]
> +  (consFns ++) <$> declareADT Right ''Int sname cons'
> +
>  declareIADT :: String -> [(String, Name)] -> Q [Dec]
>  declareIADT = declareADT Right ''Int
>
> --
> 1.8.4
>
>


-- 
Thomas Thrainer | Software Engineer | [email protected] |

Google Germany GmbH
Dienerstr. 12
80331 München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores

Reply via email to