fsharp / fslang-suggestions

The place to make suggestions, discuss and vote on F# language and core library features
345 stars 21 forks source link

Catch improper use of monadic return in async #5

Open baronfel opened 7 years ago

baronfel commented 7 years ago

Submitted by William Blum on 10/17/2015 12:00:00 AM
11 votes on UserVoice prior to migration

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 ()
  }

Original UserVoice Submission Archived Uservoice Comments

dsyme commented 7 years ago

See comment in original submission. Approved in principle, though definitely subject to a more detailed satisfactory design (not to adhoc,not specific to “async”)

Don Syme, F# Language and Core Library Evolution