0

We know that list comprehensions and do expressions are equivalent for lists. Also list comprehensions are redundant. But can someone explain how exactly do notation makes the list comprehension redundant? Is there some difference with filtering?

Noughtmare
  • 9,410
  • 1
  • 12
  • 38
xmathx
  • 31
  • 2
  • 1
    I mean, if `do` notation can do what list comprehensions can do, then this is by definition redundancy... – leftaroundabout May 06 '22 at 12:13
  • 1
    You could argue that the `MonadComprehension` extension makes `do` notation redundant by extending the older comprehension syntax to arbitrary monads. Just because two syntaxes are equivalent in power doesn't mean there aren't use cases where one is more expressive than the other. (`do` notation itself is "redundant" in the sense that you can always just use `>>=` instead.) – chepner May 06 '22 at 14:35
  • 2
    (You can also argue that list comprehensions are redundant even without `do` notation, as the Haskell Report provides [a sample translation](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-420003.11) to more basic syntax that can be used by an implementation to evaluate a list comprehension.) – chepner May 06 '22 at 14:48
  • See: https://wiki.haskell.org/List_comprehension – David Lukas May 07 '22 at 19:44

0 Answers0