dotnet / dotnet/fsharp

Bring [<Erased>] attribute to FSharp.Core and add simple features around it

Open
#18,529 5 comments 2 reactions 0 assignees View on GitHub
Area-Library Feature Request
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

This spans from the discussion of https://github.com/fsharp/fslang-suggestions/issues/538 "Erased type-tagged anonymous union types", which is from 2017 and not seeming to be implemented.

I actually like the simpler idea by @voronoipotato in his comment, because that sounds very implentable. And that's not a language feature, but just a minor addition to FSharp.Core and compiler.

1. Why not to add `[]` to F# core?
- Definition: It's an instruction to the compiler that the type can be simplified by compile-time reduction.
- What it actually does in practice depends on the compiler target (IL/JS/...)
- Fable can replace its attribute with FSharp.Core version.

2. As the first traditional F# compiler, the feature would be: Remove tagged single-case DUs:
- `[] type Phone = | Phone of string` could compile into `string`
- Benefit: Provide simpler C# interopability usage.
- Benefit: Provide more performant runtime execution while still maintaining the type safety for the developer.
- A compile-time thing, a little bit like ReflectedDefinitionAttribute. If a user breaks their own code with it (e.g. calling the type via another F# dll via ProjectReference instead of NuGet/dll-reference), it's their own problem. (Could it be erased in whole sln or is that too complex?)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.