News for hackers. Stuff that matters.
Re:Why you should learn F# by dustinmoris on Tuesday December 18, 2018 @04:08PM (#18710592)
Your sort solution limits which algorithms can be used, because you can't pass in a Func which might need an additional parameter anymore.

This is why most C# developers would use an interface for this. With an interface you add extra parameters or dependencies to the constructor of the concrete implementation. If this example wasn't sort algorithms but password hashing algorithms this would be clear.

So yeah.. it proves my point... writing good C# is not that easy, requires a lot of experience and mistakes before someone knows how to write SOLID code in C#. Thanks for helping my point!

Re:Why you should learn F# by cgrealy on Tuesday December 18, 2018 @04:22PM (#18710697)
"Your sort solution limits which algorithms can be used, because you can't pass in a Func which might need an additional parameter anymore" O RLY?

  void List<int> Sort(List<int> input, bool someParam){}

  var values = new List<int> { 9, 1, 5, 7 };
  DoSomething(x => Sort(x, true), values);
  
Thanks for proving my point that you really don't know C#.
Re:Why you should learn F# by algorithmsRcool on Tuesday December 18, 2018 @04:14PM (#18710629)
Just to be clear, you are arguing the superiority of partial application/currying here right?

Because your F# example is the same except it's trading Func<List<int>, List<int> for (int list -> int list)

Re:Why you should learn F# by AdeptusAquinas on Tuesday December 18, 2018 @04:32PM (#18710786)
Technically its passing 'a list -> 'a list, and only becoming an int array because thats the final input value. The fsharp functions are closer to the C# functions Func<List<IComparable>, List<IComparable>>
Re:Why you should learn F# by algorithmsRcool on Tuesday December 18, 2018 @04:38PM (#18710823)
Or to be even more pedantic it's

Func<T[], T[]> where T : IComparable<T>

But maybe all of that is just stronger arguments for F#'s inferred typing...

Re:Why you should learn F# by AdeptusAquinas on Tuesday December 18, 2018 @04:42PM (#18710853)
Or to be even mooooooore pedantic the fsharp functions would probably be written to be seq<'a> -> seq<'a>, so that would be Func<IEnumerable<T>, IEnumerable<T>> where T : IComparable<T> :)
Re:Why you should learn F# by dustinmoris on Tuesday December 18, 2018 @04:17PM (#18710661)
I think I just tried to say that I didn't specifically intend to write very verbose C# to make a point. I tried to write good real world production C# and then compare it to how I have seen people do DI in real world F#, which is partial application in this case. There is other ways of doing it too, but this is the most common pattern I've seen.