Worst ideas/features in programming languages?

Paul Backus snarwin at gmail.com
Tue Oct 12 17:48:04 UTC 2021


On Tuesday, 12 October 2021 at 17:25:52 UTC, max haughton wrote:
> One idea I had when bumping into this problem was something 
> like a with statement but you give it some kind of composition 
> operator, and then it joins the statements up implicitly a la 
> do notation in Haskell

You can technically do this already with `foreach` and `opApply`, 
although the result ends up looking kind of goofy:

```d
foreach (b; a)
foreach (c; b)
foreach (d; c)
e;
```

Desugars to:

```d
a.opApply(b =>
     b.opApply(c =>
         c.opApply(d => e)));
```

...which is almost the same thing as Haskell's `do` notation, if 
you replace `>>=` with `opApply` and `x <- y` with `foreach (x, 
y)`.

This similarity is perhaps why Scala uses the `for` keyword for 
[its version of `do` notation][1].

[1]: https://docs.scala-lang.org/tour/for-comprehensions.html


More information about the Digitalmars-d mailing list