Re:Intro To Pattern Matching – Covers C# 9
by thrower123 on Wednesday February 19, 2020 @10:47AM
(#22366493)
Every C# release, F# starts looking less and less compelling. There's already a level of friction, since so much of the underlying framework is C#-centric and littered with exceptions and nulls, and if you want to expose F# code to be consumed by C#, you have to dumb things down. And the tooling for F# is considerably less advanced than you get with ReSharper or even out-of-the-box in Visual Studio.
It's a bit of a shame; I suppose that is one of the reasons that some people in the F# community are really pivoting over to WASM and Fable for using F# in the browser.
Re:Intro To Pattern Matching – Covers C# 9
by Dolores12 on Wednesday February 19, 2020 @11:15AM
(#22366839)
I think you need less refactoring in F# in first place. Recently, i've tried fsbolero and was really impressed. No way I return back to C#.
Re:Intro To Pattern Matching – Covers C# 9
by SuddsMcDuff on Wednesday February 19, 2020 @11:48AM
(#22367251)
C# can only go so far down the road towards F# without introducing currying and partial application. I can't see those ever being introduced into C#.
Re:Intro To Pattern Matching – Covers C# 9
by LandR on Wednesday February 19, 2020 @12:10PM
(#22367533)
You can sorta get partial application using lambdas, or whatever they called in C#
Like a poor mans hacky partial application, one argument at a time.
namespace Bored
{
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
internal static class Program
{
private static void Main()
{
var addFive = Add.Partial(5);
addFive(6).Print(); // Prints 11
Enumerable.Range(0, 5).Select(addFive).ForEach(WriteLine); // Prints 5 to 9
}
private static Func<int, int, int> Add = (int x, int y) => x + y;
}
internal static class Extensions
{
public static Func<T2, TR> Partial<T1, T2, TR>(this Func<T1, T2, TR> func, T1 t1) => t2 => func(t1, t2);
public static void Print<T>(this T t) => WriteLine(t);
public static void ForEach<T>(this IEnumerable<T> xs, Action<T> f) => xs.ToList().ForEach(f);
}
}
Define your partial extension method for each arrity to Func. I think it maxes at 16?
Re:Intro To Pattern Matching – Covers C# 9
by fiveminds on Wednesday February 19, 2020 @10:36AM
(#22366377)
me to you can solve the same problem in 100 ways and each way can have its own tips and ticks and pors and cons! C# will be complex like c++ not for new developers only for experts!
Re:Intro To Pattern Matching – Covers C# 9
by runevault on Wednesday February 19, 2020 @10:40AM
(#22366421)
While I don't entirely disagree with you, "default" c# style won't screw you up the way default c++ will, while masterful c# will give you a non-trivial amount of the benefits if they continue to make intelligent improvements.
Will it ever be perfect? Of course not. But I feel like the direction they are taking is a reasonable one.
Re:Intro To Pattern Matching – Covers C# 9
by goto11 on Wednesday February 19, 2020 @10:41AM
(#22366435)
This is the basic dilemma for any language. You can evolve and grow bigger, or you can stay simple and pure. I think history show languages have to evolve to stay relevant - "small and elegant" languages like Scheme and Smalltalk are not widely used. But since you can't really remove existing features, evolving leads to more complex languages.
On the other hand, C# have also gotten deeper support for pass-by-reference and stack allocation which I consider more low level features. So I don't think the development is purely in functional direction.