Skip to content

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

@Thorium

Description

@Thorium

This spans from the discussion of fsharp/fslang-suggestions#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 [<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.
  2. As the first traditional F# compiler, the feature would be: Remove tagged single-case DUs:

    • [<Erased>] 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?)

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions