Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using anonymous records gives syntax error: FS0010: Unexpected symbol '|' in expression

Tags:

f#

I'm eager to use F# 4.6 anonymous records, but the compiler doesn't seem to "get it". How can I specify that I'm using 4.6? I've tried a lot of googling, but there's no documentation on how to actually tell the compiler to use the newest version(?).

Starting a new dotnet new console -lang F# -o src/App, and trying to make a dummy example:

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

Doesn't work because:

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]

my App.fsproj:

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

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

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

</Project>
like image 826
kornfridge Avatar asked Jan 16 '26 23:01

kornfridge


1 Answers

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!

like image 64
kornfridge Avatar answered Jan 19 '26 19:01

kornfridge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!