Why did you learn OCaml?

I suppose we can all tell people the technical benefits of OCaml, but I’m curious about people’s stories of why they came to OCaml.

My story, as I’ve mentioned before is that I was learning Haskell in a sort of intermittent way to learn more about functional programming, as well as playing more with the functional features in the imperative languages I already knew, including Julia. Anyway, I got a spot as a speaker at JuliaCon, so I had a t-shirt made that says “Keep Caml And Curry On” for my talk because it’s good fun to root for the other team at a conference, and it’s also annoying that Julia has the pipeline operator, but no currying/partial application.

I figured if I was going to wear a cheeky shirt like that, I should at least know some OCaml, so I did some of the tutorials on the ocaml.org and discovered it was a great language! I’d been designing a toy language in my head for a while, and OCaml seemed like the perfect tool to implement it.

So, what about you?

10 Likes

Because JavaScript has no types!

2 Likes

Some reasons that that got me interested in OCaml:

  • Strong static types with type inference
  • Really fast compilation
  • Being able to target both native and javscript (via js_of_ocaml)
  • Excellent editor tooling (This is probably not a big deal for someone used to languages that have good IDE integrations, but I had’t used another language with tools like merlin, ocp-indent, etc, and I can’t imagine working without merlin again)
  • Related to tooling, dune is perhaps the best build system i’ve used
  • Excellent resources when starting to learn OCaml (Beginning OCaml, More OCaml, Real world ocaml, etc)
  • I wanted to learn more about MirageOS
6 Likes

What drew you to OCaml/Reason over statically typed alternatives like TypeScript, Dart or Elm?

Merlin is life-altering.

1 Like

Many years ago I’ve tried OCaml out of curiosity but haven’t gone far with that (not sure what was the reason but I remember I was being confused by multitude of builds systems).

Then ReasonML appeared and I gave it a try and liked it, then OCaml ecosystem got dune/ocamlformat/… and now I’m here :slight_smile:

5 Likes

I was taught SML in college and came back to it a number of years later, but wanted something a little more ergonomic. That’s when I found OCaml :slight_smile:

I think the type system and pattern matching are the features that make me keep coming back. I really miss them when using other languages.

3 Likes

I specifically remember hearing about it in the FLOSS Weekly podcast with Randall Schwartz. @avsm was the guest speaker and he made a very compelling case for it: https://twit.tv/shows/floss-weekly/episodes/302

At the time I was trying to learn Haskell but OCaml seemed like a much more ‘down-to-earth’ FP language that still offered strong static type safety.

3 Likes

I learned OCaml because my lab’s research project used it when I started my PhD. Even though we eventually decided to switch to haskell for that project, I always had a preference for OCaml.

1 Like

Long ago (late 80s) I was an SML “bigot”. I wrote a ton of code, including distributed systems, in SML/NJ. It was a memory-hog, and while it was fast, it could only run decently on the biggest machines at the time. By the early 90s I was working at a place where big machines were a luxury, and SUN-2 (68020? 68010?) workstations were plentiful. I learned caml-light because while it was 2x slower than SML/NJ, here were 10x the machines available. With a little “parallel make” and NFS, that became a compute farm for caml-light jobs and compiles.

Caml-light (and ocaml since then) are as close as I’ve ever seen to a strongly-typed, memory-safe, systems programming language. You can get as far down as you want (and FFI to C/C++ isn’t very hard), and can employ your instincts from C in understanding the performance and resource-consumption of your code. And the fault behaviour of code is like that of C/C++ code, too – you can treat Ocaml programs from the outside as if they are C/C++ programs: something that certainly cannot be said for Java programs (for instance).

For sure I’m a type theory bigot, but that wouldn’t be enough. The runtime behaviour of caml-light/Ocaml programs was at the beginning and continues to be the biggest reason to keep using it.

ETA: I forgot another thing: caml-light and ocaml (and, IIRC, caml-heavy) all enjoy the principal type property for the core language. So when you write a bit of code, and the compiler barfs back an error, you can be sure that adding type-annotations won’t help. This is in contrast to SML, where this property does not hold for the core language. It’s amazing how useful this property is, when writing code “for real”.

10 Likes

Absolutely brilliant introductory books:

Cheers!

7 Likes

I drank some Paul Graham essay kool-aid awhile ago about Lisp being the best and searched for jobs writing Lisp. I wanted to beat averages too. Eventually I found some weirdos who were using “wants job writing Lisp” as a form of signalling, although they said we write OCaml here instead of Lisp and I said oh snap this is way better and now being required to use anything else makes me too sad to bother with.

Cheers!

5 Likes

I learned OCaml in the hope that one day my hacking productivity would reach one pico Leroy. :smile:

PS: can you guess why I learned Haskell?

6 Likes

I was taught OCaml in my first functional programming course. I instantly fell in love with the paradigm and learnt more on my own, during my personal time. I have done an internship working with a research project in OCaml, and I am heading towards a PhD diving into the Coq proof assistant’s internals, so OCaml is still on the way.

I have also learnt Scala for a 6-month project, Haskell for fun / for the elegance / to understand more theoretical concepts like monads, and Clojure in order to be able to say I have explored a bit of Lisp. Scala has too many paradigms living at the same time, Clojure has no static typing, and Haskell is still a bit too hard for me, whereas I am productive in OCaml.

2 Likes

Learned OCaml because BAP was written in it - so I simply had no choice.

4 Likes

At the time my team was looking for an alternative to Ruby for implementing a code generator. We had way too many unexpected regressions and the runtime performance sucked. None of us knew OCaml but the combination of ADTs, pattern matching, native compilation and performance got us quickly hooked.

Retrospectively I’m glad our manager had the guts to try it, it was a non-conventional move and quite a personal investment but 100% worthwhile. It improved my programming skills and it’s now my go to language for most scripting.

Every now and then you’ll get quizzical looks when you mention it to coworkers though. It’s a very hard sell in a mostly Windows shop.

3 Likes

When I started to try to learn a programming language during high school, there was a french website called le site du zero with a lot of tutorials to learn C, C++, python, … And on the forum attached to this website there was a small group of people advertising OCaml. They were not much older than me. They were not important people of the community yet. But they were nice and guiding newcomers. One of those hero is @gasche and I can’t thank him enough today :slight_smile:

9 Likes

I usually start most personal projects in F#, but a few months ago I desperately wanted a more advanced type system and better build/startup times for one of them; features that .NET couldn’t provide. Multicore wasn’t important so I gave OCaml a try.

At first I wasn’t entirely convinced, as it felt lacking in tooling and libraries (I still miss them, actually). But once I got used to Dune, Core and the Opam ecosystem, I realised I’m more productive in OCaml than in F#. Sadly, OCaml isn’t a good fit for some of my use cases, but I’m glad I’m learning it anyway!

6 Likes

A bit like @Chet_Murthy said: I’ve been seduced by OCaml from a system programming point of view: of all high level languages that I’ve tried that’s the only one who gave me the confidence that the designers were actually interested in making OCaml suitable for system programming. This shows not only in the predictability of runtime performances but also the compiler behavior (yes, that old school tooling about which everybody now use to complain about, I actually love it) and the system library.

Just to add some more personal details to make fun of myself: while a self taught programmer, I’ve been a student in France where at the time OCaml books were everywhere in university libraries. I also new OCaml was not very much used outside of french universities, therefore I though it must have been a terrible language designed solely for education and lacking all practical purposes, and actually never had a look at it.

Until one day, years later, I had a discussion with a coworker who also spent some time at INRIA, about how to be more productive than writing C while doing system programming. He told me I should give a try to OCaml because “people who love C used to also love OCaml”. This short dialog cured my prejudice and I indeed I gave it a try the same day and realized how stupid I’ve been to ignore that language for that long. :slight_smile:

7 Likes

Indeed! As Dr Madhavapeddy said about it in the podcast I referred to earlier, ‘It’s the systems programming language that everyone should know but no one knows’.

2 Likes