为什么我不能使用匹配!在计算表达式中了吗?

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

据我所知,我使用的是 F# 4.5。

但是VS2017不喜欢下面的代码

let someAsyncIntOption = async{
    return Some 1
}

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

匹配!未被识别为有效语法。

我需要做什么才能完成这项工作?

F# 4.5 was released in VS 2017 v15.8 preview 5。仅仅针对 F# 4.5 运行时是不够的;您还必须拥有 F# 4.5 编译器 才能接受该语法。 F# 4.5 编译器附带 VS 15.8 预览版 5;如果您 运行 是早于 15.8 预览版 5 的 Visual Studio 版本,那么您有一个不了解 match! 语法的旧 F# 编译器。

根据...

https://blogs.msdn.microsoft.com/dotnet/2018/07/26/announcing-f-4-5-preview/

如果您还没有...

首先,安装:

  • .NET SDK 2.1.400 预览,确保您拥有 .NET Core 中 F# 的最新位
  • Visual Studio 2017 update 15.8 Preview 5 如果你在Windows

如果您在 Visual Studio 中创建 .NET 桌面 F# 项目(从 F# 桌面开发组件),则需要使用 NuGet UI.

安装必要的位后,您可以开始使用 Visual Studio、Visual Studio for Mac 或 Visual Studio Code with Ionide 开发 F# 4.5 代码。

.NET Core SDK 2.1.400 和 Visual Studio 2017 版本 15.8 发布后,所有新项目引用的 FSharp.Core 将是 4.5.2,您将不需要执行第二次步骤.

您可能需要以 .NET Core 为目标才能工作,并且只有在将 FSharp.Core 包更新到 4.5.2 之后。

我还没有尝试过这些,但希望能有所帮助。