The “patterns” still seem to be restricted to type test … which are the first thing people tell new developers not to do in languages with pattern matching.
Well, they enable (and arguably encourage) switching on type, yes… but they also let you switch on additional conditions.
See this excerpt:
case Rectangle s when (s.Length == s.Height):
WriteLine($"{s.Length} x {s.Height} square");
break;
case Rectangle r:
WriteLine($"{r.Length} x {r.Height} rectangle");
break;
It’s not as good as Haskell, F#, SML, Scala, OCaml, or many other langauges… but it’s much better than Java and C++.
This is an important development for conservative, mainstream, “enterprisey” languages.
Oh my god, yes!!! And there are tuples too? *swoons*
yep and the tuples deconstruct as well.
Yes–pattern matching always struck me as one of the things I wish I had from the ML family.
From the outside, it’s pretty neat how they’ve kept up work on the language over time.
The “patterns” still seem to be restricted to type test … which are the first thing people tell new developers not to do in languages with pattern matching.
Well, they enable (and arguably encourage) switching on type, yes… but they also let you switch on additional conditions.
See this excerpt:
It’s not as good as Haskell, F#, SML, Scala, OCaml, or many other langauges… but it’s much better than Java and C++.
This is an important development for conservative, mainstream, “enterprisey” languages.
Does it check you’ve covered all the cases?
It seems there is a mandatory
defaultandnullcase, so in a sense all cases are covered… but I have a feeling that’s not what you meant.C# does not have ADTs, so it’s not exactly clear what “covering all cases” would mean.
Yeah, I was afraid of that. Kinda reinforces the notion that you can’t just bolt on FP to a pre-existing lang and call it done.