Problem 7 from 99 Haskell problems
Flatten a nested list structure
This is my solution:
data NestedList a = Elem a | List [NestedList a]
myFlatten :: NestedList a -> [a]
myFlatten (Elem x) = [x]
myFlatten (List (x:xs)) = x : concatMap myFlatten xs
However, I would like to understand...Why does the compiler say:
Occurs check: cannot construct the infinite type: a ~ NestedList a
Expected type: [NestedList a] Actual type: [a]