Fast and reliable programs with OCaml

Summary

Compared with Python, OCaml is a lot faster, and static checking makes code more reliable and easier to refactor. However, the syntax is less consistent, and syntax errors are harder to track down. Compared with Java, OCaml's type checking is better (no NullPointerException!), the code is much less verbose, and startup time and memory usage are lower. However, you do lose Java's binary compatibility: OCaml libraries must be recompiled when their dependencies change. Compared with Haskell, OCaml is easier to learn. It provides familiar constructs like while loops, mutable variables, and classes, making it straightforward to port existing code to OCaml. OCaml, however, lacks Haskell's type classes for convenient overloading.

OCaml is a very practical language for writing Linux applications, services, and utilities. It's reliable, fast, easy to learn, and fun to use. Additionally, it has many libraries available, can call C code easily (with ocaml-ctypes), and has a helpful and friendly community.

The Author

Thomas Leonard has a PhD in computer science from the University of Southampton, United Kingdom. He is the lead developer of 0install, a cross-platform package manager, and spent seven months of 2013 converting its 29,000 lines of Python to OCaml, learning OCaml along the way and blogging about his experiences with the language [3].

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Batsh

    Batsh kills two birds with one stone: Programs written in this language can be compiled both as Linux Bash scripts and Windows batch files.

  • Helma

    The powerful Helma application server brings new powers to the JavaScript language. We'll show you how to use Helma to build a simple RSS reader.

  • File Comparison

    With support for more than 60 file formats, diffoscope extends the power of diff beyond the plain text or HTML file.

  • Highlight Learns F#

    The new version of Highlight, the software that highlights numerous program codes in color, supports amongst other languages, F#.

  • Let's Go!

    Released back in 2012, Go flew under the radar for a long time until showcase projects such as Docker pushed its popularity. Today, Go has become the language of choice of many system programmers.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News