3 ms·
In Haskell it would be do one two because it's pretty well understood there that syntax can be a big differentiator. What's more is that this synt
by tel 12y ago
In Haskell it would be
do one
two
because it's pretty well understood there that syntax can be a big differentiator.
What's more is that this syntax adopts for the binding aspect of flatMap. So if two is dependent on one...
do output <- one
two output
which is a shortcut for
one >>= two
which might be
Promise.promisifyAll(one)
.then(function (output) {
return Promise.promisifyAll(two(output))
})
in Javascript
- jerf 12y agoHaskell has the advantage that what you've proposed is an exact conversion of the "flatMap" code, meaning that anything else that you can do with flatMap can be used with do notation, which is a lot of things beyond just tying two bits of IO code together. But in this specific case of just tying two bit of execution together, I'd observe that Erlang is One(), Two() and Go would be One() Two() and that's all regardless of whether One and Two have 0 accesses to IO or do IO dozens of times, and One and Two may also freely call other functions that do arbitrary IO with no further ceremony. The "solution" Erlang and Go offer to callback hell is simply not to have it, and pretty much no matter how you slice it, not having the problem in the first place beats any solution the JS community may or may not settle on.
- tel 12y agoThat's completely fair and accurate. The challenge is handling the genuine concurrency model then, but both Go and Erlang have good tools for doing just that. So it kind of comes down to whether you want to shave off ceremony for concurrency or for all monadic/sequencing operations at once. Honestly, that's a tradeoff.