List comprehensions (a la Haskell or Python) are much easier for humans to read than chains of List/map, List/concatMap and List/filter. This is especially true in dhall where you have to provide the type arguments to list functions. For example, I frequently have a need to generate a flat list of unstructured data from multiple lists of structured data, like the below example.
let Shape = < square | circle | triangle >
let Color = < red | green | blue >
let shape_name = \(shape : Shape) -> merge { square = "square", circle = "circle", triangle = "triangle" } shape
let color_name = \(color : Color) -> merge { red = "red", green = "green", blue = "blue" } Color
-- It is much more obvious at a glance what this is doing than the version using List/concatMap then List/map!
let shape_descriptions =
[ "${color_name color} ${shape_name shape}"
| color <- [Color.red, Color.green, Color.blue]
| shape <- [Shape.square, Shape.circle, Shape.triangle]
]
@bch29: Note that even if Dhall were to have language support for do notation or list comprehension notation, there would likely still need to be a type annotation on the bound value, like this:
[ "${color_name color} ${shape_name shape}"
| color : Color <- [Color.red, Color.green, Color.blue]
| shape : Shape <- [Shape.square, Shape.circle, Shape.triangle]
]
Would that still be usable for your use case?
Thanks for getting back to me. Yes, this would still be much better than concatMap and map.
This discussion do notation is also related, since list comprehension is a special case of do notation: https://discourse.dhall-lang.org/t/proposal-do-notation-syntax/99/7
List comprehensions (a la Haskell or Python) are much easier for humans to read than chains of List/map, List/concatMap and List/filter
I think this is a matter of personal preference. I, for example, have always found list comprehensions to be unreadable.