pelotom / burrido

Do-notation for JavaScript
MIT License
176 stars 2 forks source link

Modeling applicative do #4

Closed masaeedu closed 5 years ago

masaeedu commented 6 years ago

This is really nice, but one thing it leaves to be desired is the ability to applicatively do over independent stages. E.g. if I have:

const t = Fluture.delay(1000).map(_ => 1)
const x = yield t;
const y = yield t;
return x + y

Neither of the expressions bound to x and y are dependent on each other; thus we can use t.map(x => y => x + y).ap(t) rather than t.chain(x => t.chain(y => x + y)), resulting in the whole thing finishing in 1 second rather than 2. In Haskell (which obviously doesn't have to work under the same constraints as this library), do notation now desugars to the former rather than the latter where possible.

I can't see a way of modeling this with generators, thought maybe you might have some ideas.