I have been programming in F# for a decade and in that time I have found that when I am working within the purely functional aspects, ie. the ML lambdas, tuples, generics, etc, that everything is beautiful and consistent, and development proceeds at an order of magnitude faster than in, say, C# or Java.

However, as soon as I start using objects, with class hierarchies, constructors, polymorphism, etc, I find that I am repeatedly stopping to think about how to do things in the language, and that, overall, the development and thought process is about the same as in C#. There are some advantages to using F#, but not as significant as with functional programming.

So, the only reason I have used objects in F# is when I am forced to, namely to work within a pre-existing object oriented "framework". I have done this with ASP.NET MVC, Windows Store Apps (Win 8.1), and Android. (And, quite successfully after some initial pain).

My questions are:

  1. Did Caml become OCaml primarily to be able to interface with imperative OO languages, rather than because OO really improved the language?

  2. Could I advise budding F# programmers to avoid the OO features until they need to interface with or extend an OO framework?

As an aside, I mention that in my early days with F# I posted a question in an F# forum asking whether I should prefer the functional or OO style of programming, and the answer was emphatic:"Prefer the functional!". Since then, I've come to ask why use the OO at all?

  • 3
    $\begingroup$ You might try reading the papers of Didier Rémy and Jérôme Vouillon (who designed and implemented the object system) to get a sense. One paper is here: gallium.inria.fr/~remy/ftp/objective-ml!popl97.pdf. The sense I got is that OO programming was seen as a promising approach at the time. You'd probably have to ask one of the two above or Xavier Leroy why an object system made it into Caml Light in particular though. $\endgroup$ – Izaak Meckler May 1 '18 at 4:42
  • $\begingroup$ Thanks for the reference. Very helpful! I've glanced through it and while it goes into detail on the implementation of the OO features there is no discussion of why they are needed or what value they add to the language. As you say, it may have been a product of the time, ie. late '90s, or the further explanation may be in the numerous references. $\endgroup$ – Stephen Hosking May 1 '18 at 21:57
  • 3
    $\begingroup$ One reason is probably that some people wanted to do imperative-style programming in ML, which is visible from the design of the OCaml standard library. Now people are mostly programming OCaml functionally but the object part stayed. $\endgroup$ – xrq May 2 '18 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.