Search code examples
f#monadssyntactic-sugarcomputation-expression

Why can't I use match! in a computation expression yet?


Starting with F# 4.5, the match! keyword allows you to inline a call to another computation expression and pattern match on its result

As far as I can tell, I am using F# 4.5.

screen shot of project settings

However, VS2017 does not like the following code

let someAsyncIntOption = async{
    return Some 1
}

let someAsyncString = async{
    match! someAsyncIntOption with
    |Some 1 -> return "Some one"
    |_ -> return "None"
}

match! is not recognized as valid syntax.

What do I need to do to make this work?


Solution

  • F# 4.5 was released in VS 2017 v15.8 preview 5. It's not enough to target the F# 4.5 runtime; you also have to have the F# 4.5 compiler in order for that syntax to be accepted. And the F# 4.5 compiler comes with VS 15.8 preview 5; if you're running a Visual Studio version older than 15.8 preview 5, then you have an older F# compiler that doesn't know about the match! syntax.