@dta,
Remember, “do notation” or Roc’s “backpassing” is just syntax sugar for how it can be written otherwise as I tried to show, with the problem of the nesting making the code grow to the right when conventionally formatted and increasing levels of bracket nesting if the <|
isn’t used and without the “sugar”.
- there needs to be some deferred execution.
It looks like deferred execution but it’s just the FP way of expressing chained computations; with a slightly more sophisticated compiler than Elm’s, the functions get lifted/elided away and the “native” code is just running a linear sequence of instructions.
Without (3), Elm’s current let in
notation is the same as the do notation.
Not quite: let...in
’s don’t specify the execution order if the bindings aren’t recursively dependent, whereas function chains control the exact order.
(3) also indicates that this syntax applies only to certain specific monads like Task a
or () -> a
. It appears to have limited usefulness in current Elm, and it is unclear to me how useful it would be in an ElmPlus since I don’t know the use cases relevant to the new execution environment.
The technique applies to all monads, although current Elm has only three: Task
, Maybe
, and Result
. My first Maybe
example wasn’t so good as I just used Just
calls to create monads, but what if each of those was a call to a routine that might fail? Chaining the (implied) calls would then mean that one can concentrate the error handling to the end of the chain, and in the case of Result
, specialize the error handling dependent on the variation of the error.
ElmPlus may have at least another monad in an equivalent to the Haskell ST
monad so it can express things like STRef
to be able to express the side effect of mutation in a “pure” FP way, which when chaining monadic computations is best expressed this way and much more concisely with “do notation” or at least “backpassing”.
ElmPlus may well have more direct FFI (using Task
monads to express side effects) and some environments may find the use of TEA MUV loops awkward to use, so there very likely will be increased need of this construct to use chaining instead.
Also, if “backpassing” is used as in Roc, the use applies to any function chain and not just monadic ones…