3 ms·
C# pattern matching gets very close. I think C# can do everything except for their last example ("splitting conditional prefixes in arbitrary places"). One of t
by klauserc 2y ago
C# pattern matching gets very close. I think C# can do everything except for their last example ("splitting conditional prefixes in arbitrary places"). One of the things I miss when switching to Rust.
if foo(args)
== 0 then "null"
|> abs
> 100 then "large"
< 10 then "small"
else "medium"
That last syntax took me a while to parse in the paper, but I can imagine numerous places in our everyday code where such syntax would more concisely capture intent.
- plaguuuuuu 2y agoI'm wondering if you could use Roslyn to implement your snippet's syntax anyway.
- lptk 2y agoGenuine question, as I'm not up to date with C#'s recent developments: can C# do this? if e is ... Lit(value) and Map.find_opt(value) is Some(result) then Some(result) ... where the `...` may include many cases and may contain other Lit cases. Or this variation: ... Lit(value) and Map.find_opt(value) is Some(result) and computation(result) is Left(a) then ... Right(b) then ... ...
- tobbebex 2y agoOh but C# can do even those: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/patterns#relational-patterns https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...