top | item 40205963

(no title)

grayrest | 1 year ago

Roc does not have computation expressions and this specific syntax is the "something similar". Many other comments have noted that this feature corresponds to the IO Monad with do notation in Haskell and Computation Expressions are F#'s take on monads & friends. Roc's take on this is basically "why should someone need to know category theory to write to a file" and the relatively simple "use ! when you want to yield control to the platform" suffices until the programmer decides to dig into a full explanation.

More generally Roc is following in the footsteps of Elm in that it's an exercise in functional language minimalism. I personally like computation expressions but I think they're beyond Roc's preferred feature complexity limit. There are proposals to expand this feature either using a `?` in a `with` section that would allow for Rust-like error handling with `Result`s or a type-dependent version of `!` so the syntax could be used on something other than `Task`s. Regardless, it's expected that the IO use case is going to be the primary use case regardless so I expect they're giving people some time to play around with it and provide feedback before making further changes.

discuss

order

Akronymus|1 year ago

> "use ! when you want to yield control to the platform"

Thats quite the elegant solution indeed.

and I can certainly see the benefits to keeping it simple