代码之家  ›  专栏  ›  技术社区  ›  Chechy Levas

为什么我不能用火柴!在计算表达式中?

  •  1
  • Chechy Levas  · 技术社区  · 6 年前

    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。

    screen shot of project settings

    但是,VS2017不喜欢以下代码

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

    匹配!无法识别为有效语法。

    我需要做什么才能让这工作?

    2 回复  |  直到 6 年前
        1
  •  2
  •   rmunn    6 年前

    F# 4.5 was released in VS 2017 v15.8 preview 5 . 仅仅针对F 4.5运行时是不够的;你还必须拥有f4.5 编译程序 以便接受该语法。F#4.5编译器附带VS15.8预览版5;如果您运行的是早于15.8预览版5的Visual Studio版本,则您有一个不知道 match! 语法。

        2
  •  1
  •   just-joel    6 年前

    根据。。。

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

    如果你还没有。。。

    首先,安装:

    • 预览.NETSDK2.1.400,以确保您拥有.NETCore中F的最新位
    • Visual Studio 2017更新15.8预览5(如果您在Windows上)

    如果在Visual Studio中创建一个.NET桌面F#项目(从F#桌面开发组件),则需要使用NuGet UI将FSharp.Core包更新到4.5.2。

    一旦安装了必要的位,就可以开始用Visual Studio、visualstudioformac或visualstudio开发F#4.5代码。

    当.NET Core SDK2.1.400和Visual Studio 2017版本15.8发布时,所有新项目的引用FSharp.Core将为4.5.2,您无需执行第二步。

    可能需要将.NET Core作为目标,然后将FSharp.Core包更新为4.5.2。

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