1
  do e

is just

1
let () = e

that is, evaluate 'e' and expect it to return unit. Same for let! and do!

1
do! e

means

1
let! () = e
By on 6/7/2010 9:34 AM ()

let var evaluates the right hand side and binds its value to var.
let! var evaluates the right hand side asynchronously and 'binds' its value to var when the computation returns.

do executes a block of code (whose return value type is unit).
do! executes a block of code asynchronously and discards the result (and the block must evaluate to Async).

HTH

By on 6/7/2010 7:59 AM ()

Thanks mau - are we saying that the do and do! constructs are eagerly evaluated, whereas let and let! are lazy?

By on 6/7/2010 8:09 AM ()

One way to look at is that whenever you see a "!", that a wait and thread rendezvous is taking place - the current thread waits for the async operation to complete and then continues, possibly on a different thread. (I beleive that if the original thread is the GUI thread, that thread-affinity is maintained in this case now, no?) Without the "!" do/let behave as they would outside of an async block.

By on 6/7/2010 10:38 AM ()

(I beleive that if the original thread is the GUI thread, that thread-affinity is maintained in this case now, no?)

This depends on the behavior of the particular async object on the right-hand-side. A number of built-in operations, like Async.Sleep, do preserve the SynchronizationContext, for GUI-programming convenience.

By on 6/7/2010 10:45 AM ()

No, we are saying that let and do are eagerly evaluated.
let! and do! are asynchronously evaluated when the async is run, which I guess it's also a form of lazyness, but just in the sense that they are not evaluated until the big async is.

By on 6/7/2010 8:45 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper