There are two alternatives which I would really like to see being discussed in the Alternatives section:
Kotlin uses another builder pattern to model eDSLs like the HTML example (https://kotlinlang.org/docs/reference/type-safe-builders.html). Strangely they have not even been mentioned in the draft proposal.
The idea there is that div
for example is a simple function with a closure parameter that is called on a receiver being supplied by div
. The other elements h1
, p
etc. are then methods of the receiver object which solves gathering the results quite nicely.
Monads have actually been mentioned shortly in the draft proposal ("Function builders have no ability to interact with local bindings and are therefore substantially less general than what you can do with, say, monads in Haskell. Some specific monad-like use cases could be supported by allowing function builders to carry local state [...]") but they have not been discussed in the Alternatives section.