From 8ee2994a87f1bfc41e5d2f62723c39b67b0a37e1 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Mon, 19 Nov 2012 10:21:28 +0100 Subject: [PATCH] Switch opcode data type from normal to record constructors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, the OpCode definitions are using normal constructors: data OpCode = OpTestDelay Double Bool [String] | OpInstanceFailover String Bool (Maybe String) β¦ While this works for a few opcodes, it becomes unwieldy when dealing with a bigger number of opcode definitions and/or with opcodes having many fields. This patch changes the opcodes to record-based constructors, so that we get for free accessor functions: data OpCode = OpTestDelay { opDuration :: Double, opOnMaster :: Bool, opOnNodes :: [String] } | OpInstanceFailover { opInstanceName :: String, opIgnoreConsistency :: Bool, opTargetNode :: Maybe String } β¦ Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Adeodato Simo <dato@google.com> --- htools/Ganeti/THH.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htools/Ganeti/THH.hs b/htools/Ganeti/THH.hs index 338d40cc1..db10b4d67 100644 --- a/htools/Ganeti/THH.hs +++ b/htools/Ganeti/THH.hs @@ -526,9 +526,8 @@ genOpCode name cons = do let tname = mkName name decl_d <- mapM (\(cname, fields) -> do -- we only need the type of the field, without Q - fields' <- mapM actualFieldType fields - let fields'' = zip (repeat NotStrict) fields' - return $ NormalC (mkName cname) fields'') + fields' <- mapM (fieldTypeInfo "op") fields + return $ RecC (mkName cname) fields') cons let declD = DataD [] tname [] decl_d [''Show, ''Read, ''Eq] -- GitLab