News for hackers. Stuff that matters.
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.