I’ve stumbled upon something that seems related to this topic at large. (Funny enough found it in the Scala repo. It’s a submodule there).
This project offers a very interesting alternative approach to concurrency.
Something like that looks very promising imho.
No monads and direct style. But still all the advantages of monads (and some more on top). Please have a look at the rationale in the README on GitHub for more info.
From the research standpoint it’s not too “exciting” as it employs “only” linear- & session-types—but that’s a feature: Tried out and well understood ideas are actually preferable when doing “serious stuff” in production. At least that’s my opinion.
I don’t know at the moment how Libretto works exactly, still reading the docs and will need to have a look at the code, but it seems to provide a type-checked DSL for its purposes. (Which is maybe something that could be criticized of course. But maybe the use of a “bolted on” DSL could be healed by some integration into the Scala language, which is also a reason I’m mentioning this here).
Conceptually at least this Libretto lib seems quite well founded at first look. Pleas find some basic docs below:
https://continuously.dev/p/libretto/docs/latest/tutorial/basics.html
How and when type-, or better said, linearity-checking is implemented I’m not sure, but as far as I know Scala’s capture-checking could be used in theory to check linearity. In case that’s not possible out-of-the-box we should try to add such feature to the compiler soon as it would solve the concurrency problem (and some more, like resources) really nicely (and cross platform!).
I think “linear types” (or something with the same properties derived form checked captures) could truly change the world and finally liberate us form monads. (Yeah, no news here, but until now this wisdom did not get enough traction in mainstream—besides in some sense in Rust, Scalas “new Behemoth” ).
Also, organizing programs in form of small little “machines” that work all the time concurrently on their own, and communicate with the the outside world only through well defined (which means type checked!) message-oriented interfaces (interfaces that have a build-in notion of partial order of events, which is important in case of effects) looks very promising to me. (You can think “actors” here, but also hardware components insides SoCs, or services on the network, and a lot of more things I guess… )
[On a side note: Maybe this libs uses tagless final? If not, this could be an interesting way to implement such a DSL. Especially in addition with staging, which would allow to specialize such data-flow program at compile time, and further optimize it at runtime—similar to what @LPTK did with his linear algebra DSL⁽¹⁾. In fact linear algebra and data-streaming / -flow are even related topics as one can see in the field of AI; frankly I’ve never found the code of that Pilatus thingy, which is a real pity… The other thing is: Maybe such descriptions of concurrent data-flow programs could be even compiled directly down to hardware, or things like FPGAs; no clue though how it would relate / compare to something like SPACIAL⁽²⁾ in that case].
All that said, arguing for some supporting features in Scala for something like Libretto in case such features would be needed (I don’t know that at the moment) would not invalidate or make the idea to improve for-comprehensions even slightly less attractive! @deusaquilus just nailed it with his last comment.
⁽¹⁾ Finally, a polymorphic linear algebra language (Pearl) - ORA - Oxford University Research Archive
⁽²⁾ https://spatial-lang.org/ (Click through the first tutorial pages of Spatial to see some similarities with Libretto)