[Haskell-cafe] How about a special syntax for generalised (= MonadPlus) comprehension?

Alexey Muranov alexey.muranov at gmail.com
Sun May 15 15:20:29 UTC 2016


If i understand correctly, the main reason that generalised comprehension was
removed from Haskell 98 must have been that its syntax "collides" with the
syntax for lists.

Indeed, if

```
  [x^2 | x <- msum (map return [0..10]), x `mod` 2 == 1]
```

is made ad-hoc polymorphic, then so probably should `[]` and `[1,2,3]`.
Moreover, for consistency, the meaning of `[]` as the list type constructor
(like in `[]Int` or `[Int]`), should probably be changed to denote an
arbitrary instance of `MonadPlus` :).

My question is: why not to have a special syntax for `MonadPlus`
comprehension?  For example:

```
  {| x + y | x <- Just 1, y <- Just 2 |}
```

or

```
  [* x + y | x <- Just 1, y <- Just 2 *]
```

Then matching analogs of `[]` and `[1,2,3]` could be made:

```
  {||} :: Maybe Int  -- Nothing
  {| Just 1, Just 2, Just 3 |} :: Maybe Int  -- Just 1
```

Alexey.


More information about the Haskell-Cafe mailing list