Solution 1: Recursive version
flatten list = case list of Elem e -> [ e ] NestedList [] -> [] NestedList (head :: tail) -> flatten head ++ flatten (NestedList tail)