News for hackers. Stuff that matters.
Re:Why your F# evangelism isn't working by runevault on Tuesday May 30, 2023 @10:18PM (#36133746)
On top of your answer and the other, I still think Discriminated Unions are still a big hole in c#. I know they are supposedly working on it, but until they officially release it I'm not believing them.
Re:Why your F# evangelism isn't working by keithnz on Tuesday May 30, 2023 @11:15PM (#36134090)
It's easy enough to do DUs, they are working on it, but they are just syntactic sugar for abstract class/subclass

for instance, as an example for this https://fsharpforfunandprofit.com/posts/designing-for-correc... where a C# solution is suggested and done with DUs in F#, I wrote the equivalent DU solution in C#... https://gist.github.com/keithn/ceeeed5f7eb567e1b2333747065d1...

Only thing you don't have is exhaustive checking, which I personally don't think is much of a problem pragmatically.

Re:Why your F# evangelism isn't working by runevault on Wednesday May 31, 2023 @09:30AM (#36138176)
Exhaustive checking and locking down the base type if you don't want anyone else to extend it beyond your choices of subtypes, unless there's a way I don't know about to lock down extending to inside your binary while letting others ask for any types that references it.

There's a secondary benefit though if they allow DUs of Structs where you can have it be on the stack as a single value based on the size of the largest subtype that could be incredibly useful when you are worried about performance. Inheritance does not do that.

Re:Why your F# evangelism isn't working by ericsink on Tuesday May 30, 2023 @11:50PM (#36134264)
I too miss discriminated unions in C#.

But even more often, I find myself wishing C# blocks were expressions.

In F#, I could do this:

  let x =
      let z = whatever
      ...
      value
and z is inside a local scope.

So in C#, I want to do:

  var x =
  {
      var z = whatever;
      ...
      value
  };
Maybe it's just me.
Re:Why your F# evangelism isn't working by runevault on Wednesday May 31, 2023 @09:31AM (#36138191)
Nah it isn't just you. I probably use this more in my Rust experience then F# but when I remember it is there it is incredibly valuable.
Re:Why your F# evangelism isn't working by WorldMaker on Wednesday May 31, 2023 @01:54PM (#36141390)
I'm finding switch expressions filling that gap a lot lately. I've also picked up at some point a bad habit in "borrowing" JS' ugly IIFE pattern in C#.

    var x = (() =>
    {
      var z = whatever;
      ...
      return value;
    })();
It is not the most performant way to write that code and if the contents start to get long, refactoring to its own method starts to feel more likely, but in one-off cases, it seems fine for how ugly it is.