Monday, October 19, 2009

F#, in my mind, is the language of implementation. It provides a concise syntax when writing code "in the small" that is in many ways superior to C#. This makes F# the ideal language for writing extension methods and other methods that perform operations that are frequently repeated.

Here's a small example on how to write an extension method in F# that takes a generic IEnumerable<T> and outputs each value to the console:

Now we're cooking. I could see myself using F# for tons of utility methods where writing it in C# would simply be too cumbersome.

UPDATE (10/30/2009)

I received a question today asking how these extensions could also be used from F# as well, with the same syntax. It's not too difficult, but it does require a tiny bit of additional work. The final code would look something like this: