Jim O'Neil
Technology Evangelist
Join App Builder
Keep The Cash! Earn $100 for every app you publish! Let me know how I can help!
F# is the new kid on the block in terms of .NET languages. Currently in CTP form, it will be one of the .NET languages proper with the release of Visual Studio 2010 and the .NET Framework 4.0.
What makes F# different is its focus on being a functional language: F# is all about writing a program that indicates what you want to do, not how you want to do it (as imperative languages do). Functional languages in general have found favor in scientific and academic applications; however, they are by no means restricted to that domain. F# is actually a multi-paradigm language, meaning you can include imperative and object-oriented programming concepts as well, which bodes well for its adoption in more mainstream business applications.
There are a number of functional programming languages out there now, including Haskell, Eiffel, Scheme, and OCaml (with which F# shares its core language). One that you’re probably familiar with is SQL (Structured Query Language). Think about it, when you issue a SQL SELECT statement, you’re essentially expressing what you want, and how you get it is often a black-box operation carried out through the backend database’s query processor and optimization engine. LINQ (Language Integrated Query), which was added to the .NET Framework 3.5, similarly incorporates functional programming ideals.
One of the quickest ways to get started with F# is via F# Interactive, a Read-Evaluate-Print-Loop (REPL) tool for executing F# code. F# Interactive is part of the CTP download and can be run as a command line interface or from within Visual Studio (from the View->Other Windows menu).
Some of the core features (well, the ones I found exceptionally cool) of F# include
x
y
z
Given the multi-paradigm nature of F#, you can, however, use mutable variables (via the mutable keyword) as the snippet below shows.
mutable
Another way to handle mutable values is via reference variables, which create a pointer to memory on the heap that you can then modify via the := operator, for example:
myName
first
last
List
List.filter(…) strList
I’ve really just scratched the surface here, and since F# is a .NET language, you’ll be able to leverage the classes you’re accustomed to in C# and VB.NET (note, we used System.String.ToCharArray()in the palindrome sample above). There’s support for conditionals and loops, which themselves are functions, as well as exception handling via syntax similar to try-catch-finally. One particularly powerful feature I didn’t touch upon above is the match expression which is commonly used with yet another language concept known as discriminated unions. In fact, as you get more familiar with the functional programming style, you’ll find that pattern matching (via match) and recursion will take the place of many instances where you’d rely on if’s and for loops in imperative languages.
System.String.ToCharArray()
match
For a deeper dive into F#, check out these great on-line F# resources: