Re:TypeScript 5.0
by MrJohz on Thursday March 16, 2023 @05:32PM
(#35188991)
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.
[ Parent
| on HN ]
Pattern 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.
F# is great. Simple, small, straightforward, great interop with .NET
Also, the requirement to manually order the compilation units (files) in an XML file to ensure the compiler doesn't get confused.
They had me at features, lost me at manual compilation ordering.
Re:TypeScript 5.0
by WorldMaker on Thursday March 16, 2023 @06:05PM
(#35189446)
C# has a lot of pattern-matching support today, including an expression-switch form:
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.)
Re:TypeScript 5.0
by virtualwhys on Thursday March 16, 2023 @06:19PM
(#35189620)
> 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...