Ask HN: What do you think of F#?
Looks pretty succinct and expressive. Good IDE (VS) and nice framework (.net). Easy async programming, units of measure, quotations (as far as I understand it's similar to lisp macros). Though running on linux is pretty painful, it still can be done using mono.
So what do you think?
73 comments
[ 0.18 ms ] story [ 186 ms ] threadI'd suggest to go directly to the site http://www.fsharp.net/ - which, granted, is linked on the MS research site as well. I highly suggest looking at http://cs.hubfs.net/ as well.
Concurrency is an issue that I hope the Ocaml developers will address a bit more, though.
In order of wish list to F#:
The above would ameliorate the need for functors too, I feel.Could someone shed some light on this?
Also, F# executables tend to be orders of magnitude smaller than OCaml executables but, of course, the F# ones need a CLR installed to run them.
Both those problems have been solved in one fell swoop. Not only is the entire .NET ecosystem available, but it's a shipping, fully supported part of Visual Studio 2010. There is no reason not to use it, from the organization's perspective. Finally, all the FP programmers who've been hiding in the closet, hacking in Haskell on their personal projects, can come out! These are great days!
Learning my way around the .NET libraries (having never been a C# programmer) is the biggest hurdle. Last time I did this sort of thing on Windows, MFC and ATL were all the rage...
http://www.intellifactory.com/products/wsp/Home.aspx
---- example:
"This sample builds upon the formlet sample illustrating how formlets may be converted into flowlets for expressing sequences of web forms."
http://www.intellifactory.com/products/wsp/samples/Flowlet.a...
I started doing the Euler things etc. and did a quick dive into lexing/parsing (one strong point that your list is missing, imo). I got hooked. While I still cannot use F# for most of my things (technically it would even be possible, but try to convince your higher-ups that it is a good idea to switch to a language that they've never heard about, "because it is fun"), I use it for small things on a regular basis. You can mix functional and structural/iterative style (which is a plus in my book, the latter just _is_ faster if your program really wants to lend itself to mutable loops in places). You have a huge and well-tested library - the interaction with everything .Net is trivial.
Deployment isn't a big issue anymore: In the past you needed to either compile it statically or ship the F# stuff as well, with its status as a "first class citizen" in .Net 4 there's really no reason to back away from it anymore. It's here to stay.
I didn't have any trouble running it on mono/linux - but I've to admit that I last tried it quite a while ago.
Full Disclosure: I'm a kind of a fanboy here, I guess. The wall in my back is painted with a very nice/succinct 13 line prime number generator in F#, roughly 4cm line height, done as a decoration by my so.. ;)
It still runs great on mono. I tried it to do some examples while reading "Programming F#". It definitely brings some interesting ideas(not necessarily original but that doesn't make them any less good). I don't have any projects planned for F# but would surely love to use it sometime.
I've never had issues convincing management the biggest issue I have is convincing coworkers who don't see value in learning new languages.
The actual language was weird. Apparently it was inspired by OCaml, but I felt it was far more verbose 90% of the time, and then randomly succinct. F#'s error messages were straight up useless.
If you are looking for a good functional language, I would probably look elsewhere, but it does have the advantage that it is currently still being worked on, and it has all of the benefits that the CLR brings.
At the very least, I agree with the other comment that it will probably bring more people into functional programming, which is always a good thing.
What are your parameters for a Good functional language?
Maybe I'm seeing things wrong, but it seems that MS is not looking to make F# as mainstream as c#.
And I'll probably try my hand at Ruby or Python before F# or Lisp... I've read many posts and articles about how at least trying Lisp will make me a better programmer but I still don't want to take the plunge.
I'm not a hardcore programmer (heck I'm starting an MBA next year (1) ), and pretty pragmatic - if my tools help me build what I want, great. I don't object to learning new tools but there's a significant time cost to that, so I have to prioritize
(1) I've also read a lot of advice about why I don't want or need an MBA but I'm trying to look at it like an entry point into the business world and a networking and career advancement opportunity. I like solving problems outside of programming (making better processes and such). I'm not a salesman or marketer, but I am interested in business.
For many years I've made it a point to studiously ignore languages that come out of Microsoft, having been burned too many times by their constantly shifting and sometimes suddenly-expensive tools. Before anyone mentions price, sometimes the expense is hidden in places like what system I would have to run, with what total cost of ownership, in order to use their stuff. There may have been some unknown opportunity costs to me, but I am blissfully unaware of these and have had plenty of other fun languages to use.
Many of the 'killer features' of untyped functional languages have migrated their way into today's 'dynamic' languages like ruby, python, etc. You can use a REPL, you don't need to spend 15 minutes compiling, no static typing, etc. So in terms of 'new' things you'll learn from Clojure, you have s-exps and macros. This allows you to manipulate code as data, because the code is data.
The typed functional languages have an advanced type system, as the name indicates. In 'normal' languages, you have what I casually refer to as 'primitive types' Integers, Floats, Doubles, etc, and after that you're on your own. Typed functional languages have ADT's that allow you to model complicated systems via the types. Probably the standard example of a real-life use of this is that you can write code that will throw an error at compile time if you try to inadvertently try to add Feet and Meters. They also have pattern matching, which is pretty handy. Imagine a big if-elsif statement that will throw a compile time error if you handle bank transfers up to a million dollars, and transfers over two million dollars, but not ones that are between one and two-million dollars. You can think of both of these features as typedefs and case/if-elsif statements on crack. That's the kind of stuff you'll get from F#.
I personally think the typed functional languages have much more compelling features in this day and age. Like I said above, the features that I really dug in Lisps have made their way into most dynamic languages, and don't seem as mind-blowing as they once did. But if you really want to go crazy, it's probably worth learning at least one language from each functional sub-family at some point in time.
weird...
Scala would fall under the typed functional family. It has it's own version of ADT's and it has pattern matching. But in a lot of ways it's a hybrid OO/Functional language. A lot of the decisions in the language's design were made so that it'd play nice with Java-proper.
My initial superficial feelings about it was that it combined the worst of both worlds. It had all the popularity of a functional language, and all the nice syntax of Java.
Since then I've started writing a Droid app to get a real feel for the language, and all my superficial feelings were wrong. I like the language a lot. But it's still a little weird compared to all the other typed functional languages. You can't see as much ML in Scala as you can in F# or even Haskell.
Still, if you're stuck (or prefer) the JVM, then that's probably the typed functional language you'd want to try. That's the reason I'm using it for Droid development.
For a while there was a bug in the Dalvik VM that wouldn't let you run some Scala methods but I made a patch to fix that problem. I think it's in all releases after Android 1.6.
EDIT: Apparently Jython uses on-the-fly bytecode generation on account of being dynamic, so it can't run.
http://code.google.com/p/android-scripting/
I think it's fine to use MS stuffs for fun, hobby, side project, or even some consulting jobs (if money is good and the task is not that hard).
For me personally, I'm trying to move away from languages that requires heavy-weight tooling because I'm seeing a pattern where most people whom I consider to "know their stuff very well and can do great things" seem to come from Open Source background. They do stuff with C, *NIX, Python, Ruby, Perl, JavaScript, and various other small tools that do great things.
Just a personal observation nonetheless.
For example, there are many web startups and web consulting companies that use typical LAMP stack or "light-weight" Java stack (Spring -IoC,AOP,MVC-, Hibernate/iBatis, Ant/Mavent, Hudson, MySQL/PostgreSQL).
There are also other types of work that would require heavy help from the open source tools. One such example is embedded development. My friend works at Broadcom and he uses gcc, vim, ctags on day to day base. I'm sure companies that operate in hardware, system, and, network fields are also using open source tools heavily.
The Russian developer, who used to work at Goldman Sach and got caught sending his work to some server, used a mix of Erlang, C++, and various other tools as well so I'm guessing those big guns at Wall Streets are using open source tools for their HF trading systems.
Then there are your typical insurance companies, your typical hospitals, your typical small businesses, your typical banks, your typical grocery stores that would swear by Microsoft technology for their internal apps.
I'm not trying to say that Microsoft is not suitable for "serious businesses". I'm looking at the trend around me and it seems that Microsoft technology appears in places where people need something quick to be done and would never add major features, instead just bug fixes and small polish here and there.
Examples?
1. Active Patterns are incredibly useful. Active Patterns are the f# equivalent of 'View Patterns' in Haskell. In other words they allow you write a function that converts something into a pattern matchable form. The first example I saw of this in Haskell was the ability to write a function of the form:
dec (n + 1) = n
which performs the same function as:
dec n = n - 1
Whilst that 'cool' I didn't really see the applicability. Now you're in the f# world and trying to interact with .net libraries its suddenly amazingly powerful! Suppose you have a DOM api or something like that, that the idiomatic functional approach would involve heavy pattern matching. Hey presto - one simple function and you've wrapped up an imperative .net library and you can think of it like a discriminated union.
2. Multiple collections libraries are annoying. There's some functionally oriented stuff in the f# libraries, but sometimes its a pain to get it to interact with existing c# code - you might need to do some conversions. The Seq module works over sequences - which are instances of IEnumerable - but you find yourself looking at the LINQ extension methods, and the legacy c# functions and then the f# ones and thinking 'its one platform - why are there 4 ways of doing something?'
3. The f# compiler takes a while to generate code under Mono. I've not tried mono 2.8 yet, but as of 2.6 it takes a significant amount of time to compile projects. If you're compiling code in order to try and get a few errors, a common thing to do if you're used to using your compiler to find bugs in your code, then this becomes a bit of a productivity drag.
4. Intellisense is still useful for functional programmers. I've noted a propensity among advocates of self-described expressive languages to claim that an IDE is a crutch for weaker programmers, or perhaps produce some other ill conceived but dismissive response towards IDEs. In the past I've considered the notion that the support something like Eclipse or IDEA gives to Java programmers or Visual Studio gives to C# is something unnecessary in the functional world. My mind on this matter has been changed by two things - one being the Visual Studio support for f#. Its not as good as c#, but its at a pretty young stage and is already highly useful. I feel a lot more productive in visual studio than vim for example. The other aspect was my efforts in teaching beginners to program haskell about a year ago. I was expecting a lot of people to get stuck on Monads and combinators etc. What I didn't expect was them to become confused on basic programming issues - things an IDE would help them find solutions to more easily in a language like Java. So I'm inclined to think from these experiences that IDEs are useful, even in a succint language like f# and more importantly both to beginners and experts alike. (Assuming I can consider myself an expert.) There's already a tool that provides the intellisense support in an out-of-ide environment, and I hope that it will mature soon enough that I'll be able to use it within vim.
I have a few more minor points - but I think thats all of interest for now.
Having said that, I did find the transition painful. But that's going to be true of transitioning to FP no matter how you do it.
I'm still in a Windows environment, but I look forward to transitioning to Mono once I get FP down. At that point I'll be on an open, free stack, programming in a powerful language with tons of libraries and thousands of people to help if I have problems. What's there not to like?
http://research.microsoft.com/en-us/um/people/antr/vrr/vrr/l...
They had plans to change to a MS-PL (OSI approved) license but still hasn't happened after 2 years.
On a more practical side, the current license isn't bad, just obscure.
My point in the blog was that functional code allows you to "collect" bits of things here are there and then create your own toolset of useful stuff to do. This decreases the working set of symbols a programmer must maintain to a much more manageable level, while maximizing productivity.
It's the difference between the phonebook and having a few important people's numbers written on a piece of paper. The phone book is probably more "powerful" but the process of collecting and managing useful data from the phonebook is the important thing, not the phonebook itself.
Instead we study libraries as if they were ends to themselves. This is like trying to memorize the phone book in order to be able to call people. Yet we continue to do it.
We don't use it for everything, but it has its place.
I stopped using it when I changed jobs and left the Windows platform.
I don't really miss F#. It was fun to learn and use, but wasn't helping me write better programs quicker than C# or Python.
He said, that unlike Ocaml, in F# you still can get Null-pointer exceptions, since it's based on .NET
http://msdn.microsoft.com/en-us/library/dd233245.aspx
But if you call into non-F# libraries, including .NET framework libraries, then they can return null references. And if your F# code tries to use a null reference obtained in this way OO-style (e.g. making an instance method call through the reference), then that will indeed cause a NullReferenceException.
Obviously, it's easy to wrap 'dangerous' calls to return option values (F#'s equivalent of Haskell Maybe) instead of nulls -- it's a judgment call as to whether it's worth it for any given API.
It does have a sort-of REPL, you don't have to put one line functions inside a dummy class, and the async monad and queues are pretty handy.
It doesn't benefit from adding yet another set of collection types to the .NET API (which already has two semi-competing sets) but that is unfortunately beneficial, partly due to the next point.
The balkanisation between the .NET typesystem (class at a time, overloading ok) and the ML typesystem (sequential and no overloading) is a constant source of irritation. How to make a short name alias to the System.Console.WriteLine variadic function?
It's REPL unfortunately doesn't tie into the otherwise impressive VS intellisense and is a pain to attach the debugger to.
It hasn't proper closures (you cannot mutate variables you close over).
It's not a coherent platform, but a mishmash.