genChildren tcn cs = do funD 'children (map (genChildrenClause tcn) cs)

genChildrenClause :: TH.Name -> Con -> Q Clause
genChildrenClause tcn (NormalC name fieldTypes) = do
    fieldNames <- replicateM (length fieldTypes) (newName "x")
    let pats = [conP name (map varP fieldNames)]

        body = return . NormalB . concatLists . catMaybes
                =<< mapM (fieldChildren tcn) (zip fieldNames fieldTypes)

    clause pats body []
genChildrenClause _ _ = error "genChildrenClause: Bad Con"
