module Exercise04 where {-WETT-} xmlLight :: String -> Bool xmlLight s = null (walkOutside s) walkOutside :: String -> [String] -- check next element outside of brackets walkOutside "" = [] -- empty String is legal walkOutside (x : xs) | x == '<' = walkInside xs "" | x == '>' = [""] | otherwise = walkOutside xs walkInside :: String -> String -> [String] -- check next element inside of brackets walkInside "" _ = [""] -- illegal to finish inside brackets walkInside (x : xs) acc | x == '>' = removePair acc (walkOutside xs) | otherwise = walkInside xs (acc ++ [x]) removePair :: String -> [String] -> [String] removePair s acc | s /= "" && last s == ' ' = removePair (init s) acc -- remove trailing whitespace | acc /= [] && '/' : s == head acc && not (any (`elem` s) ['>', '<', ' ', '/']) = tail acc -- remove valid pair of ids | otherwise = s : acc {-TTEW-}