gluon-lang / gluon

A static, type inferred and embeddable language written in Rust.
https://gluon-lang.org
MIT License
3.2k stars 145 forks source link

feat: Compile block expressions as monadic sequences #886

Closed Marwes closed 3 years ago

Marwes commented 4 years ago

Rather than removing block expressions entirely, this changes them to behave as sequence (seq) expressions.

io.println "Hello"
io.println "World"

// Is now equivalent to
seq io.println "Hello"
io.println "World"
Etherian commented 4 years ago

This sounds like do blocks from Haskell but more implicit. I may be biased by my narrow perspective as an amateur hobbyist, but I have always found do blocks hard to understand and use because they obscure the mechanics and intuitions of monads.

I would personally prefer the compiler suggest lightweight combinator(s), like *> or seq, when offered consecutive monad expressions instead of silently accepting them.

Marwes commented 4 years ago

Fair point. As a counter argument, I have always thought of do blocks as a way to bridge the gap between imperative code and monadic one. So having the "default" way of writing sequential statements "just work" lets people coming from that angle still get stuff working without needing to grok monads.

Marwes commented 3 years ago

bors r+

Made it so the formatter keeps seq if it is written so both ways of writing it are equally viable now. Probably will end up removing one of the ways but for now this prevents people from writing it without seq and being confused that nothing happens.

bors[bot] commented 3 years ago

Build succeeded: