I suggest we ...

Catch improper use of monadic return in async

The following code should issue a type checking error since return () should yield an Async<unit> and return 42 should yield an Async<int>.

let f c =
async {
return ()
printfn "You passed %A and I am returning 42" c
return 42
}

Additionally the following code should issue a warning since the return statement does not actually affect the flow of execution as the name suggests (The printf statement is actually executed).

let g c =
async {
return ()
printfn "You passed %A and I am returning 42" c
return ()
}

11 votes
Vote
Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
You have left! (?) (thinking…)
William Blum shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

2 comments

Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
Submitting...
  • Don Syme commented  ·   ·  Flag as inappropriate

    I do agree that ideally this should be caught, and some kind of warning given.

    I don't specifically have a design in mind, but I am going to mark this as "planned", though subject to a detailed design, implementation and testing. I don't expect it to be a top-priority, but from the design perspective I'm ok with us looking for a solution to this specific problem.

  • Vasily Kirichenko commented  ·   ·  Flag as inappropriate

    Return in computation expressions is the monodic "return" (or "pure") and has nothing in common with return in imperative languages like C#. What's more, return usually == yield.

F# Language

Feedback and Knowledge Base