Caml-Shcaml: An OCaml Library for Unix Shell Programming

Alec Heller and Jesse A. Tov

In Proc. ACM SIGPLAN Workshop on ML (ML’08), September 2008.

Objective Caml is a flexible, expressive programming language, but for manipulating Unix processes, nothing beats the terseness and clarity of Bourne Shell:

ls *.docx | wc -l

To achieve the same effect in C requires several more lines of code and, very likely, a glance at the manual page for readdir(). Despite OCaml's excellent Unix module, which provides access to a wide variety of system calls, a task as simple as counting the .docx files in the current directory is hardly easier in OCaml than in C. The code looks largely the same.

Caml-Shcaml addresses this problem by bringing high-level abstractions for Unix systems and shell programming to OCaml. In particular, we take advantage of OCaml's type system to offer statically-checked data pipelines. External Unix processes and internal OCaml stream transducers communicate seamlessly within these pipelines. Shcaml brings other essential systems concepts into the world of typed functional programming as well, including high-level interfaces to Unix facilities for I/O redirection, signal handling, program execution, and subprocess reaping.

Available:


Publications list | Home