section :: Exp String -> [Attrib] -> Action () -> Action SectionId
section name as act = do
    sec <- newSectionId
    Value name <- name
    (xs, _) <- capture $ scope act
    x <- foldM f def{secId=sec, secName=name} as
    emit $ Section x xs
    return $ secId x
    where
        f c Unselected = return c{secUnselected=True}
        f c Required = return c{secRequired=True}
        f c (Description x) = do Value x <- x; return c{secDescription=x}
        f c (Id x) = return c{secId=x}
        f c x = error $ "Invalid attribute to section: " ++ show x
section :: Exp String -> [Attrib] -> Action () -> Action SectionId
section name as act = do
    sec <- newSectionId
    Value name <- name
    (xs, _) <- capture $ scope act
    x <- foldM f def{secId=sec, secName=name} as
    emit $ Section x xs
    return $ secId x
    where
        f c Unselected = return c{secUnselected=True}
        f c Required = return c{secRequired=True}
        f c (Description x) = do Value x <- x; return c{secDescription=x}
        f c (Id x) = return c{secId=x}
        f c x = error $ "Invalid attribute to section: " ++ show x
section name as act = do
    sec <- newSectionId
    Value name <- name
    (xs, _) <- capture $ scope act
    x <- foldM f def{secId=sec, secName=name} as
    emit $ Section x xs
    return $ secId x
    where
        f c Unselected = return c{secUnselected=True}
        f c Required = return c{secRequired=True}
        f c (Description x) = do Value x <- x; return c{secDescription=x}
        f c (Id x) = return c{secId=x}
        f c x = error $ "Invalid attribute to section: " ++ show x