genCheckFieldsUnion' :: Int -> String -> String
genCheckFieldsUnion' n name = concat [fst_line, snd_line, mid_lines, prelst_line, last_line]
    where fst_line  = concat ["int checkFields",name,"(",name,"* s1, ", name,"* s2){\n"]
          snd_line  = concat ["    if (s1->tag != s2->tag) return 0;\n"] 
          mid_lines = concat $ map mid_fn [1..n]
          mid_fn ix = concat ["    if (s1->tag == ", show (ix-1),") return checkFields",name++s_ix ix
                             ,"(&s1->val.",u_val ix,",&s2->val.",u_val ix,");\n"] 
          prelst_line = concat ["    return 0;\n"]
          last_line = "}\n\n"
          u_val  ix = (map return ['a'..'z']) !! (ix - 1)
genCheckFieldsUnion' :: Int -> String -> String
genCheckFieldsUnion' n name = concat [fst_line, snd_line, mid_lines, prelst_line, last_line]
    where fst_line  = concat ["int checkFields",name,"(",name,"* s1, ", name,"* s2){\n"]
          snd_line  = concat ["    if (s1->tag != s2->tag) return 0;\n"] 
          mid_lines = concat $ map mid_fn [1..n]
          mid_fn ix = concat ["    if (s1->tag == ", show (ix-1),") return checkFields",name++s_ix ix
                             ,"(&s1->val.",u_val ix,",&s2->val.",u_val ix,");\n"] 
          prelst_line = concat ["    return 0;\n"]
          last_line = "}\n\n"
          u_val  ix = (map return ['a'..'z']) !! (ix - 1)
genCheckFieldsUnion' n name = concat [fst_line, snd_line, mid_lines, prelst_line, last_line]
    where fst_line  = concat ["int checkFields",name,"(",name,"* s1, ", name,"* s2){\n"]
          snd_line  = concat ["    if (s1->tag != s2->tag) return 0;\n"] 
          mid_lines = concat $ map mid_fn [1..n]
          mid_fn ix = concat ["    if (s1->tag == ", show (ix-1),") return checkFields",name++s_ix ix
                             ,"(&s1->val.",u_val ix,",&s2->val.",u_val ix,");\n"] 
          prelst_line = concat ["    return 0;\n"]
          last_line = "}\n\n"
          u_val  ix = (map return ['a'..'z']) !! (ix - 1)