Remix.run Logo
louthy 2 days ago

Not discriminated unions, but they're coming (I think next version of C#). Although for now you can simulate them quite easily:

    public abstract record Either<L, R>;
    public sealed record Left<L, R>(L Value) : Either<L, R>;
    public sealed record Right<L, R>(R Value) : Either<L, R>;
Pattern-matching works well with these simulated algebraic data-types. Obviously, exhaustiveness checks can't work on 'open' types, so it's not perfect, but you can unpack values, apply predicate clauses, etc.

Other more niche features like type-providers don't exist either (although arguably those could be done with source-generators in C#). It's been a long time since I did any F#, so not sure if there's anything new in there I'm unaware of.

debugnik 2 days ago | parent [-]

That will allocate for any constructed Either though. F#'s Result and ValueOption are value-types (structs), and value-type variants recently added support for sharing fields between variants when the name and type match.

louthy 2 days ago | parent [-]

Yes, that's the limitation until the value-type DUs arrive in C# 15.

In previous versions of language-ext, I defined Either as a struct with bespoke Match methods to pattern-match. But once pattern-matching appeared in C# proper, it didn't make sense to keep the struct type.

FrustratedMonky 10 hours ago | parent [-]

Sounds like C# 15 will be it then? Everything unique about F# will be incorporated.

I guess a lot of how F# structures projects, like file order, or not using nulls, can be done by programming rigor?