I hear that F# is derived from OCaml. How true is this statement? That is to say, are the resources available for learning OCaml useful to someone who wants to learn F#? What are the major differences between the two languages (aside from the fact that F# is .NET)?
F# supports OCaml syntax directly. It might not be 100% compatible, but I think it's pretty close.
http://plus.kaist.ac.kr/~shoh/fsharp/html/index.html
Here is a list of differences (not sure how up-to-date it is)
http://plus.kaist.ac.kr/~shoh/fsharp/html/fsharp-vs-ocaml.html
This page on the Microsoft Research site details the differences between F# and OCaml.
Aside from the relatively minor language differences, I imagine the largest issue would be learning to master the .NET libraries vs. the OCaml standard library.
Anytime a new language is derived from another language there are going to be some differences. However, it's almost safe to say that F# is OCaml with the addition of .NET Framework libraries. Very similar to Boo and Python, A# and Ada, etc.
As Lou Franco said... the F# compiler will be able to compile most OCaml code using the #light directive in the code file.
The main differences are that F# does not support:
- functors
- OCaml-style objects
- polymorphic variants
- the camlp4 preprocessor
In addition, F# has a different syntax for labeled and optional parameters.
In theory, OCaml programs that don't use these features can be compiled with F#. Learning OCaml is a perfectly reasonable introduction to F# (and vice versa, I'd imagine).
The complete list of differences is here.
I always describe F# as a cousin of OCaml because OCaml has many features that F# does not have and is never likely to get. F# is more closely related to the previous CAML language. In particular, F# has very limited support for abstraction and no support for structural typing (like OCaml's objects and polymorphic variants) at all.
Contrary to what some respondants have written, F# does have (limited) support for labeled ("named") and optional arguments.
However, these are all advanced features and you can certainly start getting to grips with the basic ideas behind small-scale OCaml-style functional programming using resources about OCaml. The first major difference you will discover is larger-scale problems like encapsulation and abstraction which are solved in completely different ways in OCaml and in F#. If you want to learn how to do that in F#, the only available literature is this article on purely functional data structures.
EDIT: I have since discovered that OCaml's wonderful module system makes it easy to parameterize code over types (such as data structures) but the OOP alternatives are not only hideous but almost entirely unused on .NET. Moreover, when trying to write elegantly-parameterized data structures I hit dozens of bugs in the F# compiler because nobody has even attempted to do this before. The F# stdlib does contain some nice data structure implementations but virtually no reuse, i.e. it is a cut'n'paste job.
Cheers, Jon Harrop.
Another comparison from the perspective of an OCaml developer so it's quite biased but useful nonetheless.
if you look at the F#'s modules source code, you can find some ocaml files that are part of the (a few) F# utilities like the fsc.exe and so on. and almost all the basic programs in ocaml work in F#.
F# and OCaml are taxonimically classes in the ML family of languages, which includes a whole passle of other weird animals too. F# is newer than OCaml, and it doesn't have either functors [functions of module -> module] or row types [object classes and polymorphic variants] yet. Between them, those two simplifications probably make the learning curve easier for someone developing on the .Net platform. Sadly, those two language features are hugely powerful in OCaml, so reading the OCaml literature to gain insights into how to code for F# will probably lead to premature frustration with the latter when it's probably an excellent alternative to C# where both are available.
With regards to cross-compilation, this is an example of a product that is cross-compiled as both OCaml and F#.
The blog on the site has a little bit about the cross-compiling experience.
This question has been answered for some time now, but I was quite surprised that most of the answers say what OCaml features are missing in F# - this is definitely good to know if you want to port existing OCaml programs to F# (which is probably the motivation of most of the referenced articles). However, there are many features that make F# a different language (not just a limited version of OCaml for .NET!) Here is a couple of things that are added in F#:
- Units of measure that allow you to type-check code dealing with numerical calculations
- Meta-programming using quotations (which makes it possible to use LINQ in F# and is also essential for promissing projects like the WebSharper platform)
- Active patterns for creating abstractions for functional data types (and generally very useful feature for more complicated pattern matching applications)
- Computation expressions which is a langauge feature behing asynchronous workflows (a library for asynchronous I/O/web service/GUI programming)
- .NET compatible object-system that makes it possible to fully interoperate with the .NET platform (OCaml also has a support for objects but different - there are of course some benefits in both of the systems).
- Overloaded operators - As far as I know, OCaml doesn't have overloaded operators - in F# you can use
+
for all numeric types as well as your types that support it.
And, honestly, I think that it is also worth mentioning the Visual Studio IDE. This is not a part of the language, but it really improves the user experience (IntelliSense support in Visual Studio is really good!)
If you look at the list, there are many things that largely contributed to the popularity of F#, so it's much more than just "OCaml without functors". F# is definitely based on OCaml (and takes ideas from other languages such as Haskell) and shares many aspects with them, however there is also a lot of other things. I guess that without things like asynchronous workflows, .NET style OO and meta-programming, the Microsoft Developer Division would never include F# in Visual Studio 2010.
nemerle is more caml like than f#. and it has supperior meta programming suport.