Ocaml programs

Small Ocaml modules or programs. Feel free to use or adapt them. For convenience, I have placed most of them in the public domain.

Here are a few fragments of raw public-domain Ocaml programs.

These programs will compile using something from Objective Caml 2.00 to Objective Caml 3.11. Later versions will probably need a -pp camlp4o option. Note : some of these programs have french identifiers and comments.

Furthermore, you are assumed to know how to figure out the required libraries for a given Caml program and how to compile and execute them. In doubt try ocamlc -pp camlp4o unix.cma graphics.cma bigarray.cma toto.ml -o toto or use ocamlbuild .

Stand-alone programs

These are programs meant to be compiled and called from the shell.

redditwatcher

For tracking the evolution of multiple Reddit submissions.

mltetris

An implementation of Tetris using threads, Events and the Graphics module.

sdiw

A high quality but incomplete MIPS64 macro-assembler producing ELF output.

ATMS

An assumption-based truth-maintenance system. Takes facts, lists exclusions and environments. In french. Includes documentation. Was the term project for artificial intelligence course at P7.

FFT

A program for displaying the power density spectrum of a 16-bit, unsigned, little-endian audio file in pseudo-color palette. The FFT code has been ripped from SLIB (the Scheme library), and is quite slow. However, it only need Ocaml. Use Vi-like keys h,j,k,l for navigation ; a,s,d,q for zooming ; X to exit ; w,e and o,p to change display levels. Uses about 32 colors and thus works well on 8-bit X terms. Acceptable speed on a 500Mhz Pentium III ; quite slow on my poor Cyrix 166.

Geyik

A random-sentence generator taking a BNF description as input. The generation is not uniform but is suitable for testing a LALR parser (this was its original use). No documentation.

Gizle

Simple-minded Wavelet-based steganography.

IR

Program for synthesizing infrared remote control sequences. Works at least for Pioneer XR-P1700C. You have to build the soundcard-to-IR interface.

IRC

An IRC bot. It has minimalistic behavior, but the program being modular, it should be easy to put your own.

Karele

A program for solving the problem of tiling a rectangle with smaller rectangles of known dimensions and quantity. Was the term project for advanced algorithms course at P7.

Render

A program for rendering 2D surfaces with lighting. Term project for computer graphics. Takes ASCII datafile. Outputs PPM file. Parameters (angles, illumination) are somewhat hard to control and resolution dependent. Slow.

VT

A set of programs (C,Caml) to transform an old PC (386SX with 4Mb RAM) into a VDU displaying usage statistics for a small computer room (3 to 10 computers). Includes Ocaml modules for talking to a VT220-compatible terminal over a serial line and a layout module, plus shell for fetching news titles from the web and displaying them, plus doing rusers on a set of hosts and displaying for each connected user how much time she has spent (using the RPC code from GPS). Needs Ocamlfind. Been in service non-stop for six months. Requires ocamlrpcgen.

Wtmp

A command to read and merge a set of Linux WTMP files and display, as a function of time, the users on the different computers, computing some usage statistics and catching users that connect simultaneously on two different terminals.

Small programs and modules

xsetxmap

The standard Map and Set modules, defunctorized, made Sexplib-compatible, with some extras.

levenstein.ml

Will find the word in file (arg 2) closest to word (arg 1) according to Levenstein distance.

lexdebruijn.ml

Generates the lexicographically least binary de Bruijn sequence of given order.

line-detect.ml

Line and circle detection in sets of random points using statistical correlation.

base64.ml

Stdin to stdout base64 encoder.

convex.ml

Implements an algorithm for computing the convex hull of a set of two-dimensional points ; opens a window (module Graphics ), plots a set of random points with gaussian distribution, and draws their convex hull.

dct.ml

Computes the discrete cosine transform (DCT) of a raw 8-bit image, by decomposing it into 8x8 blocks ; arguments : height, width, filename of raw image ; output : original image as PGM file into /tmp/a.pgm ; DCT into /tmp/b.pgm ; inverse DCT of DCT into /tmp/c.pgm.

ed.ml

Will display the Levenstein editing distance matrix for its two arguments.

field.ml

Some unoptimized operations for polynomials over GF(2).

intercept.ml

Simple-minded TCP socket interceptor ; will listen to TCP port given by arg 3, and then connect to port given by arg 2 to host given by arg 1, dumping socket traffic to stdout.

ldcm.ml

Minimal doubly-linked mutable list implementation.

rc4.ml

Non-optimized, parametrizable implementation of the RC4/Arcfour stream cipher.

ringwatcher.ml

Will watch a Hayes-compatible modem at /dev/cua01 for incoming calls and log their date and time to stdout. stdin to stdout base64 encoder.

unify.ml

Implementation of Hantao Zhang's linear Robinson unification algorithm. Takes terms to unify on stdin. Includes self-contained (i.e. not Yacc or Camlp4) term parser/unparser.

wardialer.ml

War dialer, i.e. program for scanning, using a modem, a range of telephone numbers. Includes command to make US Robotics (now 3COM) Sportser modems sold in France dial as often as you like, not as often as France Telecom likes. Use carefully.

wc.ml

simple stream-based word counter.

zalgorithm.ml

Implementation of the Z string searching algorithm, from the book "Algorithms on Strings, Trees and Sequences" by Dan Gusfield (Cambridge University Press, 1997).

2009-02-08