views:

5379

answers:

12

What is the new language F# is all about? Where is that going to be useful? And what is Microsoft's future plan (release road map) regarding this language?

+1  A: 

F# allows you to easily implement functional concepts, has powerful matching facilities, and extremely flexible metaprogramming. If nothing else, you'll start to think about the structure of your programs in a very different way.

Edit: Also, I recommend checking this out: http://research.microsoft.com/fsharp/about.aspx

Cody Brocious
I'm not sure about the "extremely flexible metaprogramming". F# has no macros and only a rudimentary form of quotations that you cannot do anything with (e.g. compile). F# doesn't even have an OCaml-compatible lex implementation, let alone Camlp4-style extensible parsers.
Jon Harrop
Jon: As an aside, I found the differences between OCamlLex/OCamlYacc and FsLex/FsYacc to be few and far between. The best OCamlYacc tutorial out there (http://plus.kaist.ac.kr/~shoh/ocaml/ocamllex-ocamlyacc/ocamlyacc-tutorial/) cross-compiles into F# with minor alterations.
Juliet
+2  A: 

F# is basically bringing functional programing to the .NET platform meaning an even greater diversity and options to the already well filled .NET toolbox. It's useful since it brings both another paradigm and opens up a different view to think about problems and also since much of functional programming is about avoiding side effect it lends itself extremely well to parallelization.

Torbjörn Gyllebring
you still have to write it correctly though --to fully exploit the possibility of parallelism. But it does make things easier.
nlucaroni
The nice thing is that it encourages good practices like avoiding shared state. But yes, as always to harness the full power of it you need a deep understanding of both the technology and the problem you're trying to solve.
Torbjörn Gyllebring
+2  A: 

I think right now it would be most useful to do it for interest/learning. However, there are practical applications of functional languages in highly threaded environments. It is also a good thing to discuss in an interview if one of the interviewers has a PHd in computer science.

MidnightGun
+65  A: 

Yes, it's useful. It's useful just like any functional programming language is useful. One reason that I like to learn other languages pertains to the Sapir-Whorf Hypothesis:

The hypothesis postulates that a particular language's nature influences the habitual thought of its speakers: that different language patterns yield different patterns of thought. This idea challenges the possibility of perfectly representing the world with language, because it implies that the mechanisms of any language condition the thoughts of its speaker community.

There are certain classes of applications (like financial applications, number crunching, etc.) where functional programming REALLY shines. Outside of those scenarios, it's all about using the right tool for the right job.

Dustin Campbell has a great post on functions in F#. Curried functions are especially cool.

Let's take a simple function that increments a number by 1:

 let inc x = x + 1;;

Since functions are first-class citizens in F#, the function definition above is actually a more concise way of saying this:

 let inc = (fun x -> x + 1);;

Where it gets really fun is when you have a function with more than one parameter. In F#, technically there is no such thing, a function with two parameters is actually a function that takes one parameter and returns another function that takes the other parameter and returns the value.

So, an add function:

 let add x y = x + y;;

Is actually defined as:

 let add = (fun x -> (fun y -> x + y));;

I know, that's a bit of a mind bender at first, but it allows us to do some VERY cool things, like "partially-applied functions" (a.k.a. curried functions). Let's redefined our inc function above to be a partially-applied function based on our add function:

 let inc = add 1;;

Yes, we just called the add function and only passed it one parameter. This evaluated the first part of the function and returned another function expecting our second parameter. Very cool!

As an OOP developer, here's one way to think about functional programming: everything you currently know about functions is incompletele :). A story for you:

In the world of Object-oriented development, we tend to eat, sleep, and dream about Objects. Objects are the Manna of Life, a continued source of sustenance for our development body.

But what about Functions? Sadly, Functions exist solely to be obedient servants to the needs of their Object masters. Functions are not first-class citizens in an Object world. Functions are relegated to the dingy back alleys and filthy pool halls of development life, sent scrounging to seek out torn and tattered, week-old newspapers just to stay warm at night. They live a life of under-appreciation, doomed to forever swim just below the water level of a developer's consciousness.

jolson
I read this: "Yes, we just called the add function and only passed it one parameter. This evaluated the first part of the function and returned another function expecting our second parameter. Very cool!" and I understand what it does...but not why it's cool. I guess I'm not ready yet.
Beska
It's cool because lots of F# functions take other functions as arguments. If you're in Java or C++ or some such language, and you want to pass "add 1" as a callback, you have to actually sit down and write a stupid little function that adds 1 to its argument. In F#, you can just say "add 1" (or "+ 1") and hey presto, you have a new function!
Charlie Tangora
-- it can be difficult to imagine the coolness in 600 characters. Classes cost readibility -- each one has to be read, and takes up screen space drawing the eye in. Imagine authoring a ListControl that takes 3 policy objects - sort order, group order, and font choice -- no one will write 3 new classes just to use it, because it will make their code ugly, hard to review. Consider the berevity of `new ListControl(SortBy=(x => x.LastName), FontChoice=(x,f=>if x.Title=Manager then f.MakeBold else f), GroupBy=(x=>x.DirectReports > 0))`. You can make the control's policies clean and concise.
Aaron
You get an up-vote for me simply for introducing me to one of the most comical 'serious' programming terms I've ever heard:Curried functions.
FerretallicA
+1 for Sapir-Whorf Hypothesis, that reminds me of Julian Jaynes' "The Origin of Consciousness..." long title book.
Chris O
+1  A: 

If you're interested in aspect oriented programming, F# is the way to go... Just learn it anyway, there's no harm in learning a new language...

RWendi
Really? I didn't know F# crossed over into aspect oriented programming. What AOP concepts does it have?
Charlie Flowers
I wasn't being sarcastic here btw. But looking at this a day later, it occurs to me that perhaps you meant to type "functional programming" instead of "aspect oriented programming".
Charlie Flowers
-1, doesn't mention any aspect concepts
Casebash
+2  A: 

Since this question got nice viewership, I thought I'll share a nice article by Scott Hanselman on this topic. Hope this will help some one else.

Vijesh VP
+13  A: 

F# is all about brevity, interactivity, interoperability and a non-mainstream approach to factoring and structuring programs.

F# is useful and, in particular, is much better suited to some applications than C#:

  • Variant types and pattern matching in F# make it extremely well-suited for the manipulation of trees, which can be anything from the representation of a program inside a compiler written in F# (this family of programming languages were bred for compiler writing), computer graphics, XML handling and other applications that make heavy use of trees.

  • First-class functions provide a very concise and comprehensible way to factor programs that is very well suited to heavily abstract algorithms found in mathematical computing, including conventional data structures and algorithms.

  • F# interactive sessions are ideal for developing and running disposable programs such as massaging data and interactive technical computing. The entire .NET environment is available from interactive sessions including dynamic GUIs built with WPF, e.g. for interactive graph plotting.

The first full product version of F# was released as part of Visual Studio 2010.

Jon Harrop
A: 

i m new to programming .should i learn c# or i can follow F# langauge please advice me

You should post this in your own question.
Jin Kim
+5  A: 

Because if you do not learn it, you are going to be reduced to writing low interest line of business applications.

Why? Because C#/VB written in a standard way is full of side effects and mutable stuff. Hence, standard C#/VB code cannot take advantage of multiple cores, vector processors, GPUs, etc. as easily as F# does.

Amanda Laucher hits the ball out of the park on this issue with her lang.net presentation. She speeds up production C# code by a factor of 100x by porting it to F#. The C# code was using less than 25% of the CPU of one core.

A: 

Once you know F# you'll never go back to C#, even for OO code.

Are you high? Seriously bro
Pierreten
wow! that's a big assumption there, granted I enjoy functional programming...
AlexanderN
A: 

I'm new to F#,and Curried functions is really cool! Is partially applied function the same concept as Curried function?

David DOU
do not add questions as comments!
ygrek
+2  A: 

This video is really good at explaining "why learn F#". http://channel9.msdn.com/pdc2008/TL11/

When I was watching it, most of the time I'm thinking C# has got that, more or less, with LINQ or PLINQ up to and including CPU parallelism, but then he showed IO parallelism and it was awesome. It is really easy to express IO parallelism in F#.

Clay Lenhart