I\'ve just recently discovered the functional programming style and I\'m convinced that it will reduce development efforts, make code easier to read, make software more main
In order to achieve what you want, and to communicate it to others in your organisation you need to demonstrate your company's business being built in a better way.
Its no use using a couple of algorithms to demonstrate the power of functional programming if its totally useless for your business domain. So, take some existing code and rewrite it functionally. If you can prove through that, that it is better, people will listen to you - you've shown them a concrete, relevant example. IF you cannot, then perhaps functional programming is not the solution you've been looking for.
I came up with a little trick recently to make lambdas, passed into my extension methods look more F# ish. Here it goes:
What I wanted to do was something like:
3.Times(() => Console.WriteLine("Doin' it"));
Now the extension method for that is easily implemented:
public static void Times(this int times, Action action)
{
Enumerable.Range(1, times).ToList().ForEach(index => action());
}
What I didn't like is that I am specifying the index here: ForEach(index => action())
although it never is used, so I replaced it with a _
and got ForEach(_ => action())
That's nice, but now I was motivated to have my calling code look similar
(I never liked the "()" at the beginning of the lambda expression), so instead of: 3.Times(() => ...);
I wanted 3.Times(_ => ...);
The only way to implement this was to pass a fake parameter to the extension method, which never gets used and so I modified it like so:
public static void Times(this int times, Action<byte> action)
{
Enumerable.Range(1, times).ToList().ForEach(_ => action(byte.MinValue));
}
This allows me to call it like this:
3.Times(_ => Console.WriteLine("Doin' it"));
Not much of a change, but I still enjoyed, that it was possible to make that little tweak so easily and at the same time removing the "()" noise makes it much more readable.
Essentially, the functional paradigm is highly effective for parallel processing:
"The really interesting thing I want you to notice, here, is that as soon as you think of map and reduce as functions that everybody can use, and they use them, you only have to get one supergenius to write the hard code to run map and reduce on a global massively parallel array of computers, and all the old code that used to work fine when you just ran a loop still works only it's a zillion times faster which means it can be used to tackle huge problems in an instant.
Lemme repeat that. By abstracting away the very concept of looping, you can implement looping any way you want, including implementing it in a way that scales nicely with extra hardware."
http://www.joelonsoftware.com/items/2006/08/01.html
A good example cood be creating your own programming language using existing one, where you will have to use Monads.
With F# it's much much simplier to write parsing logic than with C#.
Take a look at this article: Functional .NET - LINQ or Language Integrated Monads?