You can't write generic monadic code in F#, instead you have to specify the monad you're working in by naming the builder associated with the expression. Your example code would look like:
let example = async {
let! a = someAsyncComputation
foo a
do! someOtherAsyncComputation
let y = somePureComputation a
return (bar y)
}
for the async
computation expression type. The 'bang' pattern (do!, let! etc.) is used when binding monadic values, while the regular keywords are used for non-monadic values.
let!
corresponds to bind (>>=)
while let
corresponds to let
in do
notation. return
corresponds to return
, while return!
is used to yield an existing monadic value. do!
is similar to (>>)
which executes a monadic value for its effects, while do
is for non-monadic effects, which has no parallel in Haskell.