I am using linux (Manjaro) and .NET Core 2.2.108 and seems the F# anonymous records are not supported while it is indicated that it is the case for example here
now available with .NET Core 2.2
I have the following F# dummy project:
ConsoleApp.fsproj
:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs"/>
</ItemGroup>
</Project>
Containing this file:
Program.fs
:
[<EntryPoint>]
let main argv =
let a = {| A = "Michelle" |}
0
dotnet
information:
$ dotnet --version
2.2.108
$ dotnet --list-runtimes
Microsoft.NETCore.App 2.2.6 [/opt/dotnet/shared/Microsoft.NETCore.App]
$ dotnet --list-sdks
2.2.108 [/opt/dotnet/sdk]
The compilation gives me:
$ dotnet build
Microsoft (R) Build Engine version 15.9.20.63311 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restoring packages for /home/perret/Desktop/ConsoleApp/ConsoleApp/ConsoleApp.fsproj...
Generating MSBuild file /home/perret/Desktop/ConsoleApp/ConsoleApp/obj/ConsoleApp.fsproj.nuget.g.props.
Restore completed in 172.04 ms for /home/perret/Desktop/ConsoleApp/ConsoleApp/ConsoleApp.fsproj.
/home/perret/Desktop/ConsoleApp/ConsoleApp/Program.fs(3,14): error FS0010: Unexpected symbol '|' in expression [/home/perret/Desktop/ConsoleApp/ConsoleApp/ConsoleApp.fsproj]
/home/perret/Desktop/ConsoleApp/ConsoleApp/Program.fs(3,13): error FS0604: Unmatched '{' [/home/perret/Desktop/ConsoleApp/ConsoleApp/ConsoleApp.fsproj]
Build FAILED.
/home/perret/Desktop/ConsoleApp/ConsoleApp/Program.fs(3,14): error FS0010: Unexpected symbol '|' in expression [/home/perret/Desktop/ConsoleApp/ConsoleApp/ConsoleApp.fsproj]
/home/perret/Desktop/ConsoleApp/ConsoleApp/Program.fs(3,13): error FS0604: Unmatched '{' [/home/perret/Desktop/ConsoleApp/ConsoleApp/ConsoleApp.fsproj]
0 Warning(s)
2 Error(s)
Is it normal?
[EDIT]
I thought Rider did update FSharp.Core
from 4.5.2
to 4.7.0
but in fact, not really:
$ sudo dotnet add ConsoleApp.fsproj package FSharp.Core -v 4.7.0
Writing /tmp/tmpBQmP0N.tmp
info : Adding PackageReference for package 'FSharp.Core' into project 'ConsoleApp.fsproj'.
log : Restoring packages for /home/perret/Desktop/ConsoleApp/ConsoleApp/ConsoleApp.fsproj...
info : Package 'FSharp.Core' is compatible with all the specified frameworks in project 'ConsoleApp.fsproj'.
error: Error while performing Update for package 'FSharp.Core'. Cannot edit items in imported files -
error: Item 'PackageReference' for 'FSharp.Core' in Imported file '/opt/dotnet/sdk/2.2.108/FSharp/Microsoft.FSharp.NetSdk.props'.
@EhouarnPerret if I test it with dotnet sdk version 2.2.2xx, 2.2.3xx, 2.2.4xx, it works fine for me. If I change the sdk to 2.2.1xx, I get the same error as yrs.
Was partially the key.
I basically had to setup the last version available in AUR:
aspnet-runtime-preview 3.0.0+100+preview.013656-2
dotnet-host-preview 3.0.0+100+preview.013656-2
dotnet-runtime-preview 3.0.0+100+preview.013656-2
dotnet-sdk-preview 3.0.0+100+preview.013656-2
Otherwise I was stuck with the version provided in the community packages which are:
aspnet-runtime 2.2.6+108-1
dotnet-host 2.2.6+108-1
dotnet-runtime 2.2.6+108-1
dotnet-sdk 2.2.6+108-1
And there is nothing available between those two out of the box.
I also would like to point out that the version of the package didn't match the version of the SDK:
Package dotnet-sdk 2.2.6+108-1
=> Actual .NET Core SDK version 2.2.108 [/opt/dotnet/sdk]
FSharp.Core
version? By the way the issue I had about updating the FSharp.Core
package to the right version came from this: https://github.com/dotnet/fsharp/issues/3656
Basically the fsproj
needs to see:
<FSharpCoreImplicitPackageVersion>4.7.0</FSharpCoreImplicitPackageVersion>
in <PropertyGroup>
. (With whatever version you want to have)
Updating the FSharp.Core
with nuget explicitly does not work.
[EDIT]
Actually it does, it just needs a little thing, see here
<PackageReference Update="FSharp.Core" Version="4.7.0"/>
is what you need to add in*.fsproj
, otherwise the build will be confused about whichFSharp.Core
to reference. This is by design wrt how the SDK works.
So basically if you are using the udpate
attribute like this here <PackageReference Update="FSharp.Core" Version="4.7.0"/>
in <ItemGroup>
it's also working.
I believe, this is actually much cleaner and standard than the previous approach.
If you don't any of those above, the version that would be used is the one "assigned" by default with the .NET Core SDK version.
| Arch Package | Actual SDK Version | Default `FSharp.Core` version |
| -----------------------------| ---------------------------- | ----------------------------- |
| `2.2.6+108-1` | `2.2.108` | `4.5.2` |
| `3.0.0+100+preview.013656-2` | `3.0.100-preview8-013656` | `4.6.2` |
So even with the package dotnet-sdk 2.2.6+108-1
and with the version 4.7.0
setup properly for FSharp.Core
the anonymous records won't compile since they are part of the 4.6
language version which is not carried by the version of the SDK in that particular package version.
FSharp.Core
really matter? In conclusion I just needed to have a more recent version of the .NET Core, the version of FSharp.Core
didn't really matter. As a matter of fact:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.5.0"/>
</ItemGroup>
</Project>
and a Program.fs
like below:
[<EntryPoint>]
let main argv =
let a = {| Diameter = 10; Area = 10; Circumference = 10 |}
0
Still compile while referencing the version 4.5.0
of FSharp.Core
.
It seems a bit weird considering that the F# version required for anonymous records is 4.6.0
: https://github.com/fsharp/fslang-design/blob/master/FSharp-4.6/FS-1030-anonymous-records.md
Now is F# language version and FSharp.Core
relate to the same thing? Not really.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.