首页 > 解决方案 > 使用匿名记录会产生语法错误:FS0010: Unexpected symbol '|' 在表达

问题描述

我渴望使用 F# 4.6 匿名记录,但编译器似乎并没有“得到它”。如何指定我使用的是 4.6?我尝试了很多谷歌搜索,但没有关于如何实际告诉编译器使用最新版本的文档(?)。

开始一个新的dotnet new console -lang F# -o src/App,并试图做一个虚拟的例子:

open System

[<EntryPoint>]
let main argv =
    let myrec = {| X=3; Y=4 |}
    printfn "Hello World from F#! test %A" myrec
    0 // return an integer exit code

不起作用,因为:

src/App/Program.fs(5,18): error FS0010: Unexpected symbol '|' in expression [src/App/App.fsproj]
src/App/Program.fs(5,17): error FS0604: Unmatched '{' [src/App/App.fsproj]

我的 App.fsproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>

</Project>

标签: f#

解决方案


Turns out it was my .NET Core Runtime that was too far behind. I didn't install the very most recent version because of the unstability warning for MacOS, but I now see that you need the MacOS-unstable version for it to support F# 4.6.

The solution was to just go to https://dotnet.microsoft.com/download/dotnet-core/2.2 and install the most recent version anyway!


推荐阅读