<p>Looks like here in StackOveflow there is a group of <strong>F#</strong> enthusiasts. </p>

<p>I'd like to know better this language, so, apart from the <a href="http://en.wikipedia.org/wiki/Functional_programming" rel="noreferrer">functional programming theory</a>, can you point me to the better starting points to start using the F# language? I mean, tutorials, how-tos, but first of all working samples to have the chance to start doing something and enjoy the language.</p>

<p>Thanks a lot</p>

<p>Andrea</p>

[{'answer_id': 36337, 'author': 'Alexandru Nedelcu', 'author_id': 3280, 'author_profile': 'https://Stackoverflow.com/users/3280', 'pm_score': 1, 'selected': False, 'text': '<p>Check out the <a href="http://msdn.microsoft.com/en-gb/fsharp/default.aspx" rel="nofollow noreferrer">F# Developer Center</a>. There is also <a href="http://cs.hubfs.net/forums/default.aspx" rel="nofollow noreferrer">hubFS</a>, a forum dedicated to F#.</p>\n'}, {'answer_id': 36369, 'author': 'vextasy', 'author_id': 3010, 'author_profile': 'https://Stackoverflow.com/users/3010', 'pm_score': 3, 'selected': False, 'text': '<p>Without doubt, you should purchase Don Syme\'s excellent book "Expert F#". The book is very well written and is suitable for both beginners and experts alike. In it, you\'ll find both introductory material and much more challenging material too. At nearly 600 pages it is good value for money.</p>\n\n<p>I found that it taught me a lot of useful techniques for writing more functional C# as well as providing all the reference material I needed to get started writing Windows hosted F# applications.  </p>\n\n<p>The book is published by Apress and has an accompanying web site at:\n<a href="http://www.expert-fsharp.com/default.aspx" rel="noreferrer">http://www.expert-fsharp.com/default.aspx</a></p>\n'}, {'answer_id': 36393, 'author': 'ljs', 'author_id': 3394, 'author_profile': 'https://Stackoverflow.com/users/3394', 'pm_score': 6, 'selected': True, 'text': '<p>Not to whore myself horribly but I wrote a couple F# overview posts on my blog <a href="http://www.codegrunt.co.uk/blog/?p=58" rel="noreferrer">here</a> and <a href="http://www.codegrunt.co.uk/blog/?p=81" rel="noreferrer">here</a>. Chris Smith (guy on the F# team at MS) has an article called \'F# in 20 minutes\' - <a href="http://blogs.msdn.com/chrsmith/archive/2008/05/02/f-in-20-minutes-part-i.aspx" rel="noreferrer">part 1</a> and <a href="http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx" rel="noreferrer">part 2</a>.</p>\n\n<p>Note you have to be careful as the latest CTP of F# (version 1.9.6.0) has some seriously breaking changes compared to previous versions, so some examples/tutorials out there might not work without modification.</p>\n\n<p>Here\'s a quick run-down of some cool stuff, maybe I can give you a few hints here myself which are clearly <em>very</em> brief and probably not great but hopefully gives you something to play with!:-</p>\n\n<p>First note - most examples on the internet will assume \'lightweight syntax\' is turned on. To achieve this use the following line of code:-</p>\n\n<pre><code>#light\n</code></pre>\n\n<p>This prevents you from having to insert certain keywords that are present for OCaml compatibility and also having to terminate each line with semicolons. Note that using this syntax means indentation defines scope. This will become clear in later examples, all of which rely on lightweight syntax being switched on.</p>\n\n<p>If you\'re using the interactive mode you have to terminate all statements with double semi-colons, for example:-</p>\n\n<pre><code>  &gt; #light;;\n  &gt; let f x y = x + y;;\n\n  val f : int -&gt; int -&gt; int\n\n  &gt; f 1 2;;\n  val it : int = 3\n</code></pre>\n\n<p>Note that interactive mode returns a \'val\' result after each line. This gives important information about the definitions we are making, for example \'val f : int -> int -> int\' indicates that a function which takes two ints returns an int.</p>\n\n<p>Note that only in interactive do we need to terminate lines with semi-colons, when actually defining F# code we are free of that :-)</p>\n\n<p>You define functions using the \'let\' keyword. This is probably the most important keyword in all of F# and you\'ll be using it a lot. For example:-</p>\n\n<pre><code>let sumStuff x y = x + y\nlet sumStuffTuple (x, y) = x + y\n</code></pre>\n\n<p>We can call these functions thus:-</p>\n\n<pre><code>sumStuff 1 2\n3\nsumStuffTuple (1, 2)\n3\n</code></pre>\n\n<p>Note there are two different ways of defining functions here - you can either separate parameters by whitespace or specify parameters in \'tuples\' (i.e. values in parentheses separated by commas). The difference is that we can use \'partial function application\' to obtain functions which take less than the required parameters using the first approach, and not with the second. E.g.:-</p>\n\n<pre><code>let sumStuff1 = sumStuff 1\nsumStuff 2\n3\n</code></pre>\n\n<p>Note we are obtaining a function from the expression \'sumStuff 1\'. When we can pass around functions just as easily as data that is referred to as the language having \'first class functions\', this is a fundamental part of any functional language such as F#.</p>\n\n<p>Pattern matching is pretty darn cool, it\'s basically like a switch statement on steroids (yeah I nicked that phrase from another F#-ist :-). You can do stuff like:-</p>\n\n<pre><code>let someThing x =\n  match x with\n    | 0 -&gt; "zero"\n    | 1 -&gt; "one"\n    | 2 -&gt; "two"\n    | x when x &lt; 0 -&gt; "negative = " + x.ToString()\n    | _ when x%2 = 0 -&gt; "greater than two but even"\n    | _ -&gt; "greater than two but odd"\n</code></pre>\n\n<p>Note we use the \'_\' symbol when we want to match on something but the expression we are returning does not depend on the input.</p>\n\n<p>We can abbreviate pattern matching using if, elif, and else statements as required:-</p>\n\n<pre><code>let negEvenOdd x = if x &lt; 0 then "neg" elif x % 2 = 0 then "even" else "odd"\n</code></pre>\n\n<p>F# lists (which are implemented as linked lists underneath) can be manipulated thus:-</p>\n\n<pre><code>let l1 = [1;2;3]\nl1.[0]\n1\n\nlet l2 = [1 .. 10]\nList.length l2\n10\n\nlet squares = [for i in 1..10 -&gt; i * i]\nsquares\n[1; 4; 9; 16; 25; 36; 49; 64; 81; 100]\n\nlet square x = x * x;;\nlet squares2 = List.map square [1..10]\nsquares2\n[1; 4; 9; 16; 25; 36; 49; 64; 81; 100]\n\nlet evenSquares = List.filter (fun x -&gt; x % 2 = 0) squares\nevenSqares\n[4; 16; 36; 64; 100]\n</code></pre>\n\n<p>Note the List.map function \'maps\' the square function on to the list from 1 to 10, i.e. applies the function to each element. List.filter \'filters\' a list by only returning values in the list that pass the predicate function provided. Also note the \'fun x -> f\' syntax - this is the F# lambda.</p>\n\n<p>Note that throughout we have not defined any types - the F# compiler/interpreter \'infers\' types, i.e. works out what you want from usage. For example:-</p>\n\n<pre><code>let f x = "hi " + x\n</code></pre>\n\n<p>Here the compiler/interpreter will determine x is a string since you\'re performing an operation which requires x to be a string. It also determines the return type will be string as well.</p>\n\n<p>When there is ambiguity the compiler makes assumptions, for example:-</p>\n\n<pre><code>let f x y = x + y\n</code></pre>\n\n<p>Here x and y could be a number of types, but the compiler defaults to int. If you want to define types you can using type annotation:-</p>\n\n<pre><code>let f (x:string) y = x + y\n</code></pre>\n\n<p>Also note that we have had to enclose x:string in parentheses, we often have to do this to separate parts of a function definition.</p>\n\n<p>Two really useful and heavily used operators in F# are the pipe forward and function composition operators |> and >> respectively.</p>\n\n<p>We define |> thus:-</p>\n\n<pre><code>let (|&gt;) x f = f x\n</code></pre>\n\n<p>Note that you can define operators in F#, this is pretty cool :-).</p>\n\n<p>This allows you to write things in a clearer way, e.g.:-</p>\n\n<pre><code>[1..10] |&gt; List.map (fun x -&gt; x * x) |&gt; List.filter (fun x -&gt; x % 2 = 0)\n</code></pre>\n\n<p>Will allow you to obtain the first 10 even squares. That is clearer than:-</p>\n\n<pre><code>List.filter (fun x -&gt; x % 2 = 0) (List.map (fun x -&gt; x * x) [1..10])\n</code></pre>\n\n<p>Well, at least I think so :-)</p>\n\n<p>Function composition defined by the >> operator is defined as follows:-</p>\n\n<pre><code>let (&gt;&gt;) f g x = g(f(x))\n</code></pre>\n\n<p>I.e. you forward-pipe an operation only the parameter of the first function remains unspecified. This is useful as you can do the following:-</p>\n\n<pre><code>let mapFilter = List.map (fun x -&gt; x * x) &gt;&gt; List.filter (fun x -&gt; x % 2 = 0)\n</code></pre>\n\n<p>Here mapFilter will accept a list an input and return the list filtered as before. It\'s an abbreviated version of:-</p>\n\n<pre><code>let mapFilter = l |&gt; List.map (fun x -&gt; x * x) |&gt; List.filter (fun x -&gt; x % 2 = 0)\n</code></pre>\n\n<p>If we want to write recursive functions we have to define the function as recursive by placing \'rec\' after the let. Examples below.</p>\n\n<p><em>Some cool stuff:-</em></p>\n\n<p><strong>Factorial</strong></p>\n\n<pre><code>let rec fact x = if x &lt;= 1 then 1 else x * fact (x-1)\n</code></pre>\n\n<p><strong>nth Fibonacci Number</strong></p>\n\n<pre><code>let rec fib n = if n &lt;= 1 then n else fib (n-1) + fib (n-2)\n</code></pre>\n\n<p><strong>FizzBuzz</strong></p>\n\n<pre><code>let (/%) x y = x % y = 0\nlet fb = function\n  | x when x /% 15 -&gt; "FizzBuzz"\n  | x when x /% 3  -&gt; "Fizz"\n  | x when x /% 5  -&gt; "Buzz"\n  | x              -&gt; x.ToString()\n\n[1..100] |&gt; List.map (fb &gt;&gt; printfn "%s")\n</code></pre>\n\n<p>Anyway that\'s a <em>very</em> brief overview, hopefully it helps a little!!</p>\n'}, {'answer_id': 36847, 'author': 'ila', 'author_id': 1178, 'author_profile': 'https://Stackoverflow.com/users/1178', 'pm_score': 3, 'selected': False, 'text': '<p>@kronoz - well thanks a lot for your long answer, that\'s a really good place to start from. I\'ll follow your advices, and look for the book @vecstasy mentioned.   </p>\n\n<p>now, let me go coding :-)</p>\n\n<pre><code>let thanksalot = "thanks a lot"\nprintfn "%s" (thanksalot);;\n</code></pre>\n'}, {'answer_id': 60865, 'author': 'Michiel Borkent', 'author_id': 6264, 'author_profile': 'https://Stackoverflow.com/users/6264', 'pm_score': 1, 'selected': False, 'text': '<p>If you have the current CTP release in Visual Studio it lets you create a F# Tutorial project, which gives you a Tutorial.fs, exactly containing what it\'s name suggests. </p>\n\n<p>That tutorial also points to a larger collection of <a href="http://code.msdn.microsoft.com/fsharpsamples" rel="nofollow noreferrer">F# examples at Microsoft</a>.</p>\n\n<p>Also, there is an F# samples project going on at <a href="http://www.codeplex.com/fsharpsamples" rel="nofollow noreferrer">CodePlex</a>.</p>\n\n<p>Hope this helps,</p>\n\n<p>Michiel</p>\n'}, {'answer_id': 105722, 'author': 'Alexandre Brisebois', 'author_id': 18619, 'author_profile': 'https://Stackoverflow.com/users/18619', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve been reading <a href="http://www.manning.com/petricek/" rel="nofollow noreferrer">Real World Functional Programming</a></p>\n\n<p>With examples in F# and C# by:Tomas Petricek</p>\n\n<p>So far I find it very good at teaching F# concepts by showing the implementations in C# on the side. Great for OO Programmers.</p>\n'}, {'answer_id': 215931, 'author': 'J D', 'author_id': 13924, 'author_profile': 'https://Stackoverflow.com/users/13924', 'pm_score': 2, 'selected': False, 'text': '<p>The first chapter of my book F# for Scientists is freely available <a href="http://media.wiley.com/product_data/excerpt/16/04702421/0470242116.pdf" rel="nofollow noreferrer">here</a>. We have a series of free F# toy programs <a href="http://www.ffconsultancy.com/dotnet/fsharp/" rel="nofollow noreferrer">here</a>. The first article from our F#.NET Journal is freely available <a href="http://www.ffconsultancy.com/products/fsharp_journal/free/introduction.html" rel="nofollow noreferrer">here</a>.</p>\n'}]
['https://Stackoverflow.com/questions/36294', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1178/']