views:

2810

answers:

10

Ok so a good few months back i started hearing about F# and all the goodness it has, i bought Don Syme's book and started reading. At first i was really excited at how elegant it seemed to make certain tasks. But then i found a problem, although the language seems great it is quite different from what i use in work which means my co-workers won't understand it if i start developing new projects in it. So because i have not had a reason to actually work with it I still havent gotten my head around F# at all.

Luckily a new solo project is on the horizon which may give me a chance to use F#. My question is how did you start developing in F#? Do your co-workers also use it?

The project will be a pretty simple WinForm application connecting to a DB. I know i can write it all in C# or VB.NET but i would like to integrate F# in there in some way. Although developing the entire application in F# would take me far too long as i am still learning what areas would you suggest i use F# for?

A: 

One of the main things we hear about F# is that it allows easier multi-threading. So I would try to find out how true that is. Pick and area like database access that you want to happen asyncronously. Try to use F# for that.

automatic
this is something they are now deliberately trying to downplay, it can help but it is in no way a panacea.
ShuggyCoUk
+6  A: 

I would be careful to not make use of it capriciously as people will need to be able to maintain any code you write, I would start using it having sold F# as a language to your colleagues and company.

I am currently simply learning the language, and I insanely want to write a C# compiler in it. F# is meant to be very good for developing compilers, the F# team had a target of writing a compiler for F# in F# in less than 10,000 lines which is pretty damn small for a compiler (they're over that now apparently but not by much).

Don Syme (inventor of F#) wrote a post about F# jobs a while ago, showing there's a real demand for F# in the real world - go check out some of the job descriptions that should give you some idea of the uses. As far as I can see it's very useful for a number of financial and scientific applications.

Personally I believe the language works well as an overall general purpose language which could replace use of a language like C# if you so wanted, and the fact Microsoft are going to release it as a fully supported language says a lot. C# steals a lot of ideas from F# for example and there is a real move toward functional programming so I'd say add 'anything you want' to the list too :-)

kronoz
+13  A: 

While F# has the same capabilities as C#, it isn't meant to be a replacement. In fact, WinForms in F# feels strange because F# is functional first, object-oriented second.

Where F# shines is in qunatatative computing. Domains like: data mining, artificial intelligence, financial analysis, etc. The types of programs that scientists and researchers typically write. Where C# and VB.NET really excel in line-of-business type apps, writing a mathematically-intensive physical simulation is a pain. (Since C# doesn't support the mathematical constructs natively.)

F# can also do parallel programming well through Async Workflows. To answer your question concisely:

You should use F# whenever you feel that you're struggling to express your ideas in your existing language. If you find yourself writing a lot of boilerplate code that you can't refactor out, then your problem domain probably isn't translating well to that language and F# might be better suited for your task.

Chris Smith
What about VB.NET and C# make them "really excel" in line-of-business apps?
Armentage
+7  A: 

I introduced F# into my work by first using it to write simple applications that only I use. For example, a tool to quickly analyse my monthly timesheet that I keep in Outlook and a tool to analyse web logs. Here F#'s computation expressions combined with the FParSec library allowed me to write the nasty code to parse and hand-off the various components of a web log line in just 30 lines of F#.

I then re-wrote our internal site monitor (which I had previously written in C#) in F# with the advantage that F#'s asynchronous workflows allowed me to check each of the 60 web sites we monitor in parallel (with ease).

I did find that the take-up of F# at work was not as great as my enthusiasm for it led me to imagine it might have been. I think it's a big step to go from C# to F# and needs some real investment of effort and time to begin using it fruitfully. I also find that unless I keep revisiting it I quickly get rusty.

Other people had tinkered with my C# site monitor to the point where I wasn't sure I still fully understood it. Since re-writing it in F# no one has yet made a change!

I made a decision to keep F# GUI programming to a minimum, at least initially, until the language is better integrated with Visual Studio and ASP.Net and focus on using F# to do the crunching and use C# for the interaction.

vextasy
"Since re-writing it in F# no one has yet made a change!" lol
Kalmi
+1  A: 

I would echo the previous answer saying that using F# in GUI is 'strange'. No Designer, for starters.

In any case F# only just came out in CTP, so I wouldn't be writing any production code in it yet!

I am also the only one in my department playing with F#, but I sometimes send mails to my colleagues with little interesting snippets (Units of Measure for example) to whet their appetites.

I would also go with writing a few home-made utilities as practice. I just wrote myself a script for counting LinesOfCode (in 38 lines).

Benjol
"In any case F# only just came out in CTP, so I wouldn't be writing any production code in it yet!"We've been doing this for quite some time... if a tools that good the temptation to use it is too strong. Plus side is you get more input into the bug fixing/feedback in the early stages when it is most amenable to change.
ShuggyCoUk
True, I've had answers directly from Don Symes. That hasn't yet happened with Anders... :)
Benjol
A: 

I have used F# on our project for ad-hoc scripting (as I work in an investment bank it will never be approved for production use until it is part of a formal microsoft release).

This means we have a few fairly simple F# scripts kicking around in source control which coworkers can either use blindly (I include comments at the top of the script showing how it can be run using fsi.exe), but more often will lead to them getting hold of a copy of Expert F# and finding out more about it.

Hopefully by the time the RTM comes out, a good proportion of my team will already have a certain depth of F# knowledge, so will make implementation of some of our libraries in F# an option.

Chris Ballard
+2  A: 

I recommend getting a copy of Artificial Intelligence: A Modern Approach if you can find a cheap copy. The class I took was only a semester long so we didn't get to code up many of the examples, but as I read it, the topics screamed "program me in a functional language" even though it's targeted towards imperative languages. Almost every algorithm discussed in the book includes a pseudo-code block, and online code samples in many languages.

So, to sum up: AI:MA will explain many algorithms that lend themselves very easily to declarative-style functional programming (search, logic, decision trees, learning, neural networks) but no support in terms of how to write in a functional programming language, and especially not F# specifically.

drhorrible
A: 

I have been using f# to generate java code from mysql schema as well as as script. I find that the using F# helped in creating parsers quite easily. If I have a choice between python and ocaml I would use ocaml/f# over python.

A: 

We are using F# for most of our development which is mostly web development these days. One area where this is very helpful is in cross-compiling F# quotations to JavaScript and building AJAX apps in pure F#.

toyvo
A: 

I have used it to poll the web for the 'webolarity' of languages.
I only have studied F# for a week now and alone in my spare time, but polling the web and creating a table was only a few lines of code and very easy!

The results (the html table) can be find here : http://phelsen.wordpress.com/2009/11/27/webolarity/

Peter