4 ms·
C# doesn't have algebraic data types and pattern matching though, right? I'm not the same person, but at least for me that's one of the big advantages of Rust,
by MrJohz 4y ago
C# doesn't have algebraic data types and pattern matching though, right? I'm not the same person, but at least for me that's one of the big advantages of Rust, and it's one of those features that outside of Rust you only really find in ML-family languages. I know it's possible to simulate it partially using sealed classes in some languages, but that's always seemed like a lot of boilerplate in comparison.
- roebk 4y agoPattern matching was recently added to C#. I can't say quite how well it's been embedded into the language. I always hear great things about F#, ADTs, pattern matching, nice type system and it integrates nicely into the rest of the .NET ecosystem.
- WorldMaker 4y agoC# has a lot of pattern-matching support today, including an expression-switch form: https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals... C# can fake algebraic data types in some ways/some cases. Though if you are expecting to do a lot of it you are still better off in F# or C#/F# hybrid projects. (F# of course being a proper ML-family language.)
- virtualwhys 4y ago> it's one of those features that outside of Rust you only really find in ML-family languages Or in Scala, technically not an ML, but is as close as you'll get in a nominally typed language. enum RGB: case Red, Green, Blue def log(x: RGB) = x match case Red => print("red") case Green => print("green") // error, not exhaustive Obviously Scala can do a lot more, including GADTs, which Rust will never have until HKTs are supported. Ton of powerful languages to choose from these days, good times...