As we generate forthcoming objects with template Haskell anyway, also generate the a predicate indicating if an object is forthcoming.
Signed-off-by: Klaus Aehlig <[email protected]> --- src/Ganeti/THH.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Ganeti/THH.hs b/src/Ganeti/THH.hs index 0af9254..9e131b1 100644 --- a/src/Ganeti/THH.hs +++ b/src/Ganeti/THH.hs @@ -1091,8 +1091,18 @@ buildObjectWithForthcoming sname field_pfx fields = do [todict, fromdict] instArray <- genArrayObjectInstance name (simpleField "forthcoming" [t| Bool |] : fields) + let forthPredName = mkName $ field_pfx ++ "Forthcoming" + let forthPredDecls = [ SigD forthPredName + $ ArrowT `AppT` ConT name `AppT` ConT ''Bool + , FunD forthPredName + [ Clause [ConP (mkName real_nm) [WildP]] + (NormalB $ ConE 'False) [] + , Clause [ConP (mkName forth_nm) [WildP]] + (NormalB $ ConE 'True) [] + ] + ] return $ concreteDecls ++ forthcomingDecls ++ [declD, instJSONdecl] - ++ accessors ++ lenses ++ [instDict, instArray] + ++ forthPredDecls ++ accessors ++ lenses ++ [instDict, instArray] -- | Generates an object definition: data type and its JSON instance. buildObjectSerialisation :: String -> [Field] -> Q [Dec] -- 2.2.0.rc0.207.ga3a616c
