Earlier quoted context omitted.
Honest question: why would anyone make a list comprehension that's multiple levels deep? Isn't the purpose of comprehensions to provide quick-and-dirty inline for loops, where a full for loop is too verbose?
For me it’s very rare and used where I would write something like concatMap in Haskell. citiesByState = { 'WA': ['Seattle', 'Spokane', 'Olympia'], 'OR': ['Portland', 'Salem'], 'CA': ['San Francisco', 'Los Angeles', 'San Diego'], } cityToState = {city: state for state, cities in citiesByState.items() for city in cities} I would generally avoid multiple levels in a comprehension but there are some very simple two-level…
cityToState = Map.fromList
[ (city, state)
| (state, cities)
For multiple “nested loops”, I generally prefer do-notation over both list comprehensions and combinators such as concatMap, unless the structure is simple enough that the combinator version is much shorter.