sweet-fantasies icon indicating copy to clipboard operation
sweet-fantasies copied to clipboard

Bugs in do-notation

Open raimohanska opened this issue 10 years ago • 5 comments

I'd like to use do-notation for Async monad (the thing in my blog). I did some experimenting and found a couple of issues with the do macro.

So firstly, I cannot

$do {
  x <- Async.of("cats")
  y <- Async.of("dogs")
  Async.liftIO(function() {
    console.log(x, y)
  })
}

.. because the macro requires the last expression to be a return.

I'm happy though that this indeed works:

$do {
  x <- Async.of("cats")
  y <- Async.of("dogs")
  return console.log(x, y)
}

The second problem is that multiple returns don't work, so I can only 1 "naked IO" per do-block. See failing test case: 9940a1e791da5eec1f937717af127c63d825a8e9

Also, var bindings in the "tail" do not work as in

$do {
  x <- Async.of("cats")
  y <- Async.of("dogs")
  both = x + y
  return console.log(both)
}

There's a failing test case for this too, at 3fb4326860c413d532c8fc3b88b0ee3433fd464f.

Having said this all, I still want to thank you for all these Sweet Fantasies! I think there's good stuff on the way but it needs some polishing first. Sorry for not having time to start looking for fixes yet.

raimohanska avatar Dec 18 '13 22:12 raimohanska