News for hackers. Stuff that matters.
Re:F# Basics An Introduction to Functional Programming for .... by MichaelGG on Thursday April 08, 2010 @01:12PM (#1250251)
There are plenty of things. From real-world experience, F# code ends up taking a bit less than half the amount of lines as C# does. More interestingly, the number of type annotations can be as little as 1/20th as in C#.

The benefit comes from that many "small" things you do in C# become much nicer in F#:

C#:

  int target;
  int someValue;
  if (dict.TryGetValue("key", out someValue)) {
      target = someValue * 100;
  } else {
      target = 42; // default
  }
F#:

  let target = match dict.TryGetValue "key" with
               | true, x -> x * 100
               | _	   -> 42 // default
Not only is the code more concise in F#, we get another benefit too. The temporary value x, needed because of the use of out params in C#, no longer exists in the F# version. In C#, this temp val escapes its needed scope - it should only be needed in the branch where it's used, but instead it's now a normal local.

A more large scale win is any async code. In F#, you can use the async workflow (monad), and with 1 character (!), you make the compiler emit code that'd take at least 10 extra lines in C#. Inside an async workflow, a let! (example: let! foo = bar.AsyncGetResponse()) is like calling bar.BeginGetResponse, bar.EndGetResponse, while preserving the current exception handlers and all locals. It makes heavily async code trivial to write, where in C#, it's near impossible.

Re:F# Basics An Introduction to Functional Programming for .... by runT1ME on Thursday April 08, 2010 @01:48PM (#1250346)
Thanks for this! Looks like a great language. Its a shame it targets the CLR and Mono is so crippled.

If it was on the JVM, looks like a serious competitor to Scala with some distinct advantages (! operator for sure) along with a little simpler syntax.

Re:F# Basics An Introduction to Functional Programming for .... by scott_s on Thursday April 08, 2010 @02:46PM (#1250503)
Keep in mind that F# is very similar to OCaml. OCaml compiles to native executables, so while it's not for the JVM, you should be able to use it on most platforms.
Re:F# Basics An Introduction to Functional Programming for .... by omellet on Thursday April 08, 2010 @04:45PM (#1250845)
How exactly is the CLR crippled?
Re:F# Basics An Introduction to Functional Programming for .... by bmason on Thursday April 08, 2010 @05:31PM (#1251046)
The statement was that Mono is crippled. Last I checked, Mono was lagging at least one major release behind Microsoft's CLR. So if you're using fancy new features, you'll probably have to refactor to gain cross platform support, and even then you may encounter bugs and memory leaks.
Re:F# Basics An Introduction to Functional Programming for .... by omellet on Friday April 09, 2010 @07:50AM (#1252406)
You're right, I misread it.