<p>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.</p>

<p>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.</p>

<p>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).</p>

<p>My questions are: </p>

<ol>
<li><p>Did Caml become OCaml primarily to be able to interface with
imperative OO languages, rather than because OO really improved the
language?</p></li>
<li><p>Could I advise budding F# programmers to avoid the OO features until
they need to interface with or extend an OO framework?</p></li>
</ol>

<p>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?</p>

CC BY-SA 3.0
2018-05-01T04:42:48.960Z
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: http://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.
Izaak Meckler
CC BY-SA 3.0
2018-05-01T21:57:48.137Z
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.
Stephen Hosking
CC BY-SA 4.0
2018-05-02T20:39:41.827Z
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.
xrq
<object-oriented><ocaml>
Why did Caml become OCaml? (or, why use objects in F#?)
Stephen Hosking
# Why did Caml become OCaml? (or, why use objects in F#?)

(Asked by: username_0 on 2018-04-30)

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?

**Tags:** object-oriented, ocaml
> **Comments:**
> **username_1**: 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: http://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.  
> **username_0**: 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.  
> **username_2**: 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.  

---

## 0 answers

