3 ms·
Like every language I learned to program in I had a project and then decided to use that language with that project. I have to admit the first project was kille
by fleitz 16y ago
Like every language I learned to program in I had a project and then decided to use that language with that project. I have to admit the first project was killer, it took me a long time to even get the code compiling. But once I had finished and looked at the lack of code I was sold that this was the way to go.
There is a really cool tutorial on writing the game of life in 32 lines of F# or writing the game of life that executes on the GPU using a similarly small amount of code.
http://tomasp.net/blog/accelerator-life-game.aspx http://tomasp.net/blog/accelerator-life-game.aspx
Start with a small project and learn the language, once you have a quite specific 'How do I do X?' question there are plenty of examples. I've never been the type person who could pick up a language from a book.
If you're doing ASP.NET google for F# + MVC + NHAML. There is a great tutorial for getting an ASP.NET project going in F#.
I'd say the primary thing that you need to learn for F# is how to convert loops to recursive functions and vice-versa. Also, look into the pipe operator, and figure out how to abuse the hell out of Seq.reduce and Seq.scan.
If you like LINQ and lambda's in C# you'll probably like F#, I'd say that's what really got me interested, I ended up loving LINQ and lambdas and wanted to know more about this whole F# deal. Using the pipe operator makes the whole thing look much more pretty IMHO.
[0..10]
|> List.map (fun x -> x*x)
|> List.reduce (fun a b -> a + b)
vs.
Enumerable.Range(0,10)
.Select(x => x*x)
.Aggregate((a,b) => a+b)
- gcampbell 16y agoMinor refactoring note, since F# seems to bring that out in me: you could change the last bit to "List.reduce (+)". Or you could do the whole thing as "[0..10] |> List.sumBy (fun x -> x*x)"
- trezor 16y agoThanks for the response. The game of life sample was pretty awesome, and the way HW acceleration was added just made it neater. And yes, I like LInQ quite a bit. I love how it lets you write your code a lot more declarative and in the process allows you to speed up your code by avoiding creating new collections while defining your transform. Now I've added a F# Interactive tab to my console2 session and I guess I'll see if I manage to get into F# properly this time around :)