Bring [<Erased>] attribute to FSharp.Core and add simple features around it
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.
-
Why not to add
[<ErasedAttribute>]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.
-
As the first traditional F# compiler, the feature would be: Remove tagged single-case DUs:
-
[<Erased>] type Phone = | Phone of stringcould compile intostring - 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?)
-
If there's a problem we can't solve, there's a simpler version of the problem we can solve :). Then when that succeeds we can use the insights gained to solve more complex problems. Thanks for making a feature request for this!
If someone who has time/energy I wouldn't mind trying to chip away at this problem on a weekend if I had someone to bounce ideas off of. I would probably be pretty slow and sporadic in effort, but it doesn't seem like that would be an issue for this one.
I personally think this should go through its own suggestion, so it's explicitly outlined what's supported, what's not and what are the use-cases.
@voronoipotato :
What is the scope you would want to tackle in the first prototype, is it about erase single-case DUs ?
I think it is a good starting point, and the same Erased attribute could be later reused for more features.
It does make sense to open that specific piece (just single case DUs) as a new suggestions, to give a space where people can oppose it if they see fit.
I can be available to you for your bouncing ideas :)) In general, as a good starting point, https://deepwiki.com/search/there-is-a-language-suggestion_1dc96af3-d80c-4e23-b0b0-f00b8a8c2dc6 is quite good for bouncing off ideas (I typically prompt it to give me 3 different ideas on how to solve a problem, often at least one of them is a direction I would choose as well :-D)
TLDR: 👍 to start small 👍 to make a separate suggestion for it