Playing with Caml Light on DOS

Frederic Cambus September 27, 2023 [DOS] [Caml] [Compilers]

OCaml has been on my radar for some years now, and I think it was MirageOS which sparked my interest in the language. Lately, I started reading more about OCaml and its ecosystem, and indulged myself in an historical detour.

For more background information on Caml and the Caml Light implementation in particular, please refer to "A History of Caml". Distribution archives for Caml Light are available here.

The oldest DOS version available on Inria site is Caml Light 0.6, and I was able to find Caml Light 0.5 on the Simtel archives. The recovered files are available here, along with documentation for the 0.6 version.

Here is an ANSI logo tribute which was drawn especially for this post:

Caml Light

Caml Light is implemented as a bytecode compiler which made it highly portable. It is possible to create executables using the CAMLC.EXE command, but please be aware that the resulting binaries are not standalone when using the default linking mode, and the runtime system (CAMLRUN.EXE) is required to run them.

The latest available release of Caml Light for DOS is version 0.7 released in 1995.

Compared with the UNIX version, one of the drawbacks is that it is not possible to interface with C functions. Another one is that we cannot use Ctrl+D to send the EOT character to quit the REPL, one should type quit();; instead to invoke the quit system function to get back to the DOS command interpreter.

On the plus side, the DOS version supports graphics primitives using the Borland Graphics Interface CGA.BGI driver for CGA graphic cards, or EGAVGA.BGI for EGA and VGA cards.

The development environment can be bootstrapped as follows:

mkdir -p ~/dos/caml386
cd ~/dos/caml386
wget https://caml.inria.fr/pub/distrib/Oldies/cl7pcbin.zip
unzip cl7pcbin.zip

When using FreeDOS, we need to add the following in FDAUTO.BAT:

set PATH=c:\caml386\bin;%PATH%
set CAMLLIB=c:\caml386\lib
set GO32TMP=c:\tmp

Alternatively, when using DOSBox instead, we need the following in dosbox.conf:

[autoexec]
mount c ~/dos
path=c:\caml386\bin
set CAMLLIB=c:\caml386\lib
set GO32TMP=c:\tmp
set GO32=driver c:\caml386\dev\vesa_s3.grd gw 800 gh 600
c:

The last configuration line is optional and only required for using the graphics primitives. DOSBox emulates an S3 Trio64 by default, so we need to use the VESA_S3.GRD driver.

Once we are done installing, this gives us Caml Light 0.7:

C:\>camlc -v
The Caml Light system for the 80386 PC, version 0.7
  (standard library from c:\caml386\lib)
The Caml Light runtime system, version 0.7
The Caml Light compiler, version 0.7
The Caml Light linker, version 0.7

We can then start playing with the example programs bundled with the Caml Light distribution.

This is a screenshot from the "Color Wheel" program:

Caml Light - Color Wheel

Another program showing graphics animation of sorting algorithms:

Caml Light - Showsort

And finally the interactive "Spirals" program:

Caml Light - Spirals

For the more adventurous reader, there also was a user contributed DOS port of OCaml 1.00. Have fun!

Back to top