dmjio
10/18/2013 - 1:08 AM

C# Combinator

C# Combinator

// (.) :: (b -> c) -> (a -> b) -> a -> c, haskell version
// (.) f g x = f (g x)
// Haskell usage
// plusThree = (+1) . (+1)
//We sort of do that here, but we need to implement currying

Func<Func<int,string>, Func<string,int>, string, string> combinator = (f, g, x) => {
	return f (g (x));
};

Func<int,string> intoString = (x) => x.ToString ();
Func<string,int> stringToInt = (x) => Convert.ToInt32(x);
Console.WriteLine (combinator (intoString, stringToInt, "33"));

//Output "33"