F #: Hello, World

About a year later, we are waiting for the next release of Microsoft Visual Studio and almost the most delicious new product promises to be F # - a functional language through the eyes of the guys from the Cambridge laboratory of Microsoft Research. This language is completely new and is now at the lick stage in Microsoft Research laboratories. Microsoft positions F # as one of the main languages ​​for .Net along with C # and VB.Net, which most likely means that sooner or later, very many .Net programmers will encounter it. Like many developers, I have never come across purely functional languages, but the principle “Prepare a sleigh in summer” has not been canceled. This article is my personal little “Hello F #”.

So, you can feel the novelty right now. For this we need Visual Studio 2008 and Microsoft F #, September 2008 Community Technology Preview . After installing the latter, a new project branch will appear in the studio - Visual F #.
Let's create a console application and after some time spent googling, try to say hello to the world:
// подключаем лайт-синтаксис <br/>
#light <br/>

// C# : using System; <br/>
open System<br/>

// скажем миру привет <br/>
printfn "Hello, World! What is your name, user?" <br/>

// а как нас зовут? C# : var name = Console.ReadLine(); <br/>
let name = Console .ReadLine()<br/>

// определим функцию, которая будет говорить "привет" аргументу who. <br/>
// приблизительный аналог на C#: <br/>
// public delegate void SaySomethingDelegate(string toWho); <br/>
// SaySomethingDelegate sayHello = who => Console.WriteLine("Hello, {0}!", who); <br/>
let sayHello who = printfn "Hello, %s!" who<br/>

// привет, Хабрахабр! <br/>
sayHello name<br/>

// а в функциях можно использовать и стандартные методы .Net Framework: <br/>
let sayHelloDotNet who = Console .WriteLine( "Hello from F# via .Net, " + name + "!" )<br/>

// и опять привет! <br/>
sayHelloDotNet name<br/>

// в качестве бонуса посчитаем числа Фибоначчи :) <br/>
let rec fib i = // рекурсивная функция от одного аргумента <br/>
match i with // которая смотрит на что похож этот аргумент <br/>
| 1 | 2 -> 1 // если он 1 или 2, то возвращаем 1 <br/>
| i -> fib(i-1) + fib(i-2) // если он похож только на себя - то рекурсивно вызываем эту же функцию <br/>

// смотрим, что у нас получилось <br/>
printfn "%i" (fib 20)<br/>

* This source code was highlighted with Source Code Highlighter

Output of our program:
Hello, World! What is your name, user?
Hello, Habrahabr!
Hello from F# via .Net, Habrahabr!

Like this. The language is pretty nice. Yes, FP is a fundamentally different area than traditional languages ​​like C #. Yes, F # is still damp. Yes, there are not enough features. Yes, there is a Nemerle , but it is unlikely that MS will fundamentally change F # over the next year.
If there is interest in this topic, I will try to compose something else, at least this area is very interesting to me.