News for hackers. Stuff that matters.
Re:TypeScript Is Surprisingly OK for Compilers by zkldi on Friday August 18, 2023 @04:25AM (#37172755)
C# doesn't have anything resembling proper pattern matching. C#s pattern matching is akin to a marginally improved switch or if/else-if chain. C#s pattern matches aren't exhaustive, and the compiler doesn't properly check them at all.[0]

There are no proper sum types in C#, so 80% of the point isn't even there.

    enum Season
        {
        Spring,
        Summer,
        Autumn,
        Winter
    }
     
...

    int PatternMatch(Season season) =>
    season switch {
        Season.Spring => 1,
        Season.Summer => 2,
        Season.Autumn => 3,
        Season.Winter => 4,
        // compiler can't prove the above code is exhaustive because no proper sum types
        // compiler needs nonsensical branch here that diverges
        _ => throw new ArgumentException("Invalid enum value for command", nameof(command)),
    };
Re:TypeScript Is Surprisingly OK for Compilers by hardware2win on Friday August 18, 2023 @04:27AM (#37172764)
>compiler can't prove the above code is exhaustive because no proper sum types

Thats because c#s enum is not "closed"

https://github.com/dotnet/csharplang/issues/3179

Re:TypeScript Is Surprisingly OK for Compilers by paddim8 on Wednesday August 23, 2023 @02:26AM (#37232462)
These things are not about pattern matching but about other language features.