Ziff-Davis Enterprise 
DevSource: Microsoft Developer Resource
Add OnsArchitectureLanguagesTechniquesUsing VSForums
 
Home arrow Languages arrow Exploring the New F# Language
Exploring the New F# Language
By John Mueller

Rate This Article:
Add This Article To:
Exploring the New F# Language
( Page 1 of 4 )

Why do we need yet another language in a programming world full of them? This article shows that F# has something interesting to offer.

Over the years, I’ve used all kinds of languages, everything from Assembler and ROM BASIC to LISP and Prolog to PHP, Java, C#, and VB.Net. In fact, I regularly write applications using any of the host of languages I’ve learned because I believe there’s a language for every task. Let’s just say I’m not stuck in a rut. So, why would someone even need a new language such as F#? After all, the world has many languages that I haven’t even tried yet. For example, I’ve heard of ML (http://en.wikipedia.org/wiki/ML_programming_language), OCaml (http://caml.inria.fr/l), and Haskell (http://www.haskell.org/), but I haven’t used them. Well, F# brings a couple of new things to the table that really are very exciting including (in order of excitement for me):

  • Full .NET accessibility
  • Complete command line scripting use
  • Integration with Visual Studio 2005, Visual Studio 2008, and the Visual Studio 2008 Shell (download it at http://msdn2.microsoft.com/en-us/vsx2008/products/bb933751.aspx)
  • Cross-platform availability (Windows 2000, Windows Server 2003, Windows XP, Vista, Windows Server 2008, or Linux/Macintosh with Mono)
  • Strong data typing and type inference
  • Good application performance inline with using C#
ADVERTISEMENT

The most important consideration for C# and VB.NET developers is that F# is a functional language. It gives you another tool, but a tool with a completely different way of looking at the programming problem. F# is a great tool when you need to perform pattern matching, require easy thread safe concurrent applications, or carry out complex list processing. Because you can create F# libraries and use them with your C# or VB.NET application, you can mix F# with these other languages to create applications that execute quickly, perform better, and require less maintenance, while producing better applications.

What is a Functional Language?

There are many ways to categorize languages. The categories are there to help people decide which language is best for a particular use, but often they end up confusing more than helping. F# is a functional language, contrasted to C# and VB.NET, which are imperative languages. A functional language is one that relies on equations. When you use a functional language, X = Y means that X and Y are equal. You aren’t assigning the value of Y to X. An equation defines a specific relationship; there isn’t any state to consider or mutable data to manage. Consequently, working with a functional language has certain advantages over an imperative language because the contents of an identifier (the F# version of a variable) remain the same throughout the execution of the application. It doesn’t matter which processor works with the identifier because the identifier always remains the same. F# applications don’t suffer the concurrency problems that you must deal with when using an imperative language.

Functional languages also tend to produce succinct code. You create the application using equations and then supply data to those equations. An equation can be a constant, a function, an object, or anything else that F# supports. Consequently, when you look at an identifier, you could possibly see anything. Some developers will have a very hard time understanding this concept, but you’ve already worked with it to some extent if you’ve creating an eXtensible Stylesheet Language Transformation (XSLT) application because XSLT has a strong functional language bias.

At this point, you have enough information to start working with F#. I don’t want you to become overwhelmed with all of the details just yet. In fact, this article will tend to show you that F# really isn’t that hard to begin using. Of course, functional languages are far more complex than I’ve indicated here. You can see some good write-ups about functional languages at http://en.wikipedia.org/wiki/Functional_programming_language and http://www.cs.nott.ac.uk/~gmh//faq.html. And in the weeks to come, I’ll be providing you with more examples and explanations here on DevSource.

Why Do We Need F#?

Many of the functional languages of the world are used for academic purposes; you typically don’t see them used in real world development. The lack of a practical use is unfortunate because functional languages have a lot to offer. F# is an effort to make functional languages useful in the real world. Not only can you mix and match F# with C# or VB.NET, but you can use it to create scripts and perform other complex tasks on its own. It’s important to remember the three strengths of F# though when you consider using it:

  • List processing
  • Pattern matching
  • Concurrent programming strategies

The final use is one of the most important considerations as developers begin writing applications for multi-core processors. A valid criticism of multi-core processor use today is that applications can’t make use of the additional processors because they aren’t written to exploit them. As a result, many applications use just a single core and the remaining cores tend to remain idle or at least underused. While you can write perfectly acceptable thread safe applications using C# or VB.NET, using F# tends to enforce the requirements for concurrency and make writing these applications considerably easier. F# applications also enforce the atomic access requirements for concurrency that can prove difficult to provide with other languages. You get these benefits without extra work on your part because they are part of the F# language. The Microsoft Web site at http://research.microsoft.com/fsharp/fsharp.aspx tells you more about the reasons that you’ll want to add F# to your toolbox.



 
 
>>> More Languages Articles          >>> More By John Mueller
 



DevSource video
Devsource Video Series
Manipulating Society through Technology
Jeremy Bailenson, Director of the Virtual Human Interaction Lab at Stanford University, talks about virtual reality, avatars, Moore's law, how real world behaviors influence online reality, and societal manipulation through technology!
>> Play video
>> Read article
>> See all videos
DevLife Blog

Julia explores the Robotics Studio! (It's for more than you think.)

MSDev Blog

Messages for Bill Gates!

Make it Work
.NET makes runtime type checking a breeze. See what Peter has to say about it in this week's tips!
News
Microsoft Counts on App Support for Vista
Microsoft has taken pains to demonstrate that Windows Vista will have ample application support.
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.