The OCaml Journal

Subscribe to the OCaml Journal today and read our growing repository of fascinating articles on the functional programming language OCaml:

  • Learn how to create GUI applications and visualizations quickly and easily.
  • Exploit multi-cores and CPUs with concurrent and distributed programming.
  • Manipulate XML data using pattern matching.
  • Work with interoperable web services.
  • Use our source code to kick off your own projects.
  • Cut-n-paste any or all of the OCaml code from the journal into your own work at no extra cost!

All included when you subscribe to the OCaml Journal for just 52p per article!

Subscription

All existing articles

Testimonials

"These articles have really helped me..." - Alp Mestan (read the full review)

"Last week I subscribed to the OCaml Journal, and that has been a very good decision." - Daniel de Kok (read the full review)

"THANKS for all of your great work!" - Don Brady, Comintel Inc.

"Lots of interesting stuff for anyone looking into the OCaml language!" - Roland Kaufmann.

"I am finding the articles interesting, especially on combinators..." - Iain Gray.

"I am particularly impressed by the wide range of content and the depth of the articles." - Dr Colin Frayn, Cercia Ltd.

Free articles

The following articles are available for free to non-subscribers:

  • Introducing the OCaml programming language (May 2007)

    "The OCaml programming language is developed at INRIA in France and was first released in 1996. Since then, OCaml has excelled in a variety of application domains and has become one of the world's most popular functional programming languages. The most notable developments include..."

If you would like to see articles on a particular topic then please register on-line and let us know.

Subscription articles

The following articles are available in the archives to subscribers:

  1. How to Leverage Pattern Matching (8th June 2007)

    "Compared to conventional programming languages, OCaml takes dynamic dispatch to a whole new level using an approach called pattern matching. This article guides the reader through the fundamental concepts that underpin pattern matching before providing some examples demonstrating the power of pattern matching in general programming..."

  2. The Essence of Functional Programming (23rd June 2007)

    "OCaml is fundamentally a functional programming language and the use of functions instead of objects often leads to shorter and clearer code. Indeed, many of the benefits of functional programming are already known to OO programmers in the form of design patterns..."

  3. GUI Programming: A Sudoku solver (10th July 2007)

    "Powerful cross-platform GUI applications can be developed quickly and easily in the OCaml programming language. This article describes the design and implementation of a cross-platform GUI application for solving sudoku puzzles..."

  4. Data structures in the Standard Library (24th July 2007)

    "The OCaml standard library includes a wealth of mutable and immutable data structures that cover a wide variety of needs. This article introduces all of the data structures provided by the OCaml standard library and describes when and how to use each of them..."

  5. Exploiting Tail Recursion (9th August 2007)

    "Recursion is essential to functional programming and practical use of functional programming languages and a functional style requires the ability to write recursive functions that do not consume stack space. Function calls that require no stack space are called tail calls. This article describes the use of tail calls to write robust and efficient tail recursive functions in OCaml..."

  6. Optimizing a simple bytecode interpreter (23rd August 2007)

    "As a high-performance functional programming language, OCaml is perfect for writing interpreters. These programs involve a wide variety of different techniques from lexing and parsing to various methods of evaluation, compilation, simplification and rewriting. All of these techniques will be described in future OCaml Journal articles and this article describes the implementation of three progressively optimized interpreters for a minimal byte code language..."

  7. Combinator Heaven (8th September 2007)

    "The ability to write higher-order functions that compose other functions in interesting ways is one of the most powerful forms of abstraction provided by the functional programming paradigm. Such functions are known as combinators . This article describes the basic concepts behind combinators with a variety of examples to demonstrate how practically useful this form of functional abstraction can be..."

  8. Using lex and yacc (24th September 2007)

    "The tool stack bundled with the OCaml distribution provides some awesome functionality. The ocamllex and ocamlyacc tools provide a mainstream approach to the parsing of data. This article introduces the concepts of lex and yacc-based parsing and describes the use of these tools in implementing robust and efficient parsers quickly and easily..."

  9. A simple FFT implementation (8th October 2007)

    "Writing an implementation of the Fourier transform is an excellent lesson in algorithm design and optimization. Moreover, the Fourier transform is one of the most essential tools in numerical computing, with applications ranging from spectral analysis in science to the multiplication of large integers in mathematics. This article describes the design, implementation and optimization of a high-performance FFT implementation in OCaml..."

  10. Balanced binary search trees (23rd October 2007)

    "Immutable data structures are a core concept in functional programming and balanced binary trees are the single most important such data structure. The OCaml programming language allows balanced binary tree implementations to be written clearly and efficiently. This article describes the design and implementation of a basic balanced binary search tree data structure similar to that of the built-in Set module..."

  11. Introduction to OpenGL (12th November 2007)

    "OpenGL is the defacto-standard cross-platform graphics API and provides an efficient way to leverage the high-performance hardware accelerators found in almost all modern computers. The OCaml programming language has unusually good support for OpenGL with the LablGL library providing an elegant interface to OpenGL on all three major platforms. This article introduces OpenGL programming using OCaml, demonstrating how functional programming can be leveraged to produce visualization software that is simple and efficient..."

  12. Camlp4 3.10: parsers and macros (23rd November 2007)

    "The latest OCaml tool stack includes a revamped preprocessor called camlp4 that serves several purposes including providing extensions to the OCaml language that allow parsers to be embedded in ordinary OCaml code as well as the ability to extend the syntax of OCaml itself by writing macros. This article explains how camlp4 can be used to write general parsers and OCaml syntax extensions..."

  13. Festive Fun with OpenGL and GTK+ (12th December 2007)

    "This article marries the ability to render high-quality graphics in real-time using OpenGL with the ability to build GUI applications using GTK+. Specifically, a small program is developed that builds upon functionality encountered in previous articles to render a decorated christmas tree with snow in real time..."

  14. Parser Combinators (28th December 2007)

    "Certain applications are extremely well suited to functional programming and parsing is one of them. Specifically, the ability to write functional combinators that allow parsers for everything from integers up to symbolic expressions to be composed is more general and provides more opportunity for code reuse than the use of conventional parser generators such as ocamllex and ocamlyacc. This article explains how parser combinators may be designed and implemented in OCaml, using the standard example of a calculator..."

  15. Implementing a simple ray tracer (10th January 2007)

    "Ray tracing is a simple but powerful approach to photorealistic rendering and implementing a ray tracer is an excellent way to learn a programming language and, in particular, to learn about graphics and optimization in the context of numerical algorithms. This article walks through the design and implementation of a basic ray tracer that provides real-time visualization a scene using OpenGL in a GUI application that provides the user with rendering options using a GTK+ menu..."

  16. Factoring numerical methods using combinators and functors (24th January 2007)

    "The same concepts that make functional programming a powerful paradigm for symbolic manipulation can also be applied to numerical methods. This article describes the basic concepts of factoring using higher-order functions and functors in the context of numerical algorithms such as function minimization..."

  17. Language-oriented programming: The Term-level Interpreter (9th February 2008)

    "Modern software is using a wider variety of languages than ever before. The ability to parse and interpret these languages is of growing importance. Fortunately, OCaml inherits incredibly powerful language features (algebraic data types and pattern matching) for program manipulation from its predecessors and augments these with an excellent suite of tools and libraries. This article explains how OCaml can be harnessed to write a complete term-level interpreter for a programming language in only a tiny amount of code..."

  18. High-fidelity graphics with OpenGL 2 (25th February 2008)

    "The single most important advancement made in consumer-level graphics accelerators in recent years was the advent of the programmable graphics pipeline. OpenGL 2 introduces the high-level GLSL shader language as a way to program the graphics pipeline. This article describes how the latest version of the GLCaml bindings for OCaml allow GLSL shaders to be used to improve the fidelity of high-performance graphics using per-pixel Phong shading..."

  19. Run-time compilation with LLVM (8th March 2008)

    "The Low-Level Virtual Machine (LLVM) project brings high-performance static and JIT compilation to code generators written in the OCaml programming language. This article describes the basic use of LLVM from OCaml including both static and JIT compilation, argument passing, control flow and the compilation of expression trees..."

  20. Getting the most out of Static Typing (26th March 2008)

    "The OCaml language arms programmers with one of the most sophisticated static type systems of any general-purpose programming language. This static type system can be used to remove large classes of common bugs that are otherwise tedious or impossible to track down. The benefits in terms of programmer productivity and program reliability are tremendous. However, leveraging such a type system is an art that requires significant effort to learn. This article describes idiomatic OCaml style and a variety of techniques that can be used to leverage the static type system in order to catch errors earlier and more easily..."

  21. Labeled and Optional arguments (10th April 2008)

    "The OCaml programming language provides a variety of useful features that are not found in many other functional programming languages. This is why OCaml is widely accepted as a functional language for practical use. Labeled and optional function arguments are two related features that can be used to great effect in simplifying interfaces. This article introduces the syntax required to define and use both labeled and optional arguments in OCaml and describes some pedagogical uses of these features, with references to existing libraries, as well as examining some of the problems often encountered by programmers using these features..."

  22. Language oriented programming: Term Rewriting (25th April 2008)

    "An interesting and powerful alternative to the conventional term-level interpreter is called term rewriting. Rather than reducing expressions down to values, term rewriting simply evaluates expressions by performing substitutions and the result is another expression. This approach is particularly well suited to computer algebra systems such as Mathematica but is also an underappreciated alternative to dynamically-typed programming languages that can integrate useful features like pattern matching and make techniques like partial specialization far easier. This article describes how a simple term rewriter can be constructed and introduces the concept of private variant type constructors in the process..."

  23. Porting and optimizing the SciMark2 benchmark (10th May 2008)

    "The SciMark2 benchmark is a suite of numerical algorithms that were originally collated into a benchmark for scientific computing on the Java platform. Porting this benchmark to OCaml provides an excellent tutorial on the implementation of efficient numerical algorithms using the current OCaml implementation. The results illustrate the strengths and weaknesses of the current OCaml implementation in terms of performance..."

  24. Implementing a simple XML-RPC client and server (23rd May 2008)

    "XML-RPC is a protocol for remote procedure calls that is built upon the XML format. Method calls are packaged up by the client as an XML request sent via HTTP to the server whereupon action is taken and a response is packaged up and returned in the same way. This article describes how a complete client-server pair using XML-RPC can be designed and built from scratch in OCaml using only the XML-Light and OcamlNet libraries..."

  25. Real-time Finite Element Materials simulation (10th June 2008)

    "Finite Element Materials simulations (FEMs) model a continuous volume of material by breaking it down into a discrete representation with many finite parts. This article describes a simple but fun program that simulates the dynamics of a 2D system of particles and springs in real-time. The program visualizes the results using OpenGL..."

  26. Tricks with recursion: knots, modules and polymorphism (22nd June 2008)

    "This article introduces some of the design patterns found in functional programming. The phrase "untying the recursive knot" refers to the ability to remove direct recursion from value and type definitions through the use of parameterization. OCaml's recursive modules allow recursion to cross module boundaries. Polymorphic recursion allows functions to call themselves with different type parameters. This article introduces all of these functional design patterns with illustrations and worked examples..."

  27. Foreign Function Interfaces: Calling C from OCaml (10th July 2008)

    "Although the OCaml programming language offers many improvements over older languages such as C, C++ and Fortran the need to interoperate with native code can still arise. The two most important uses for native code interoperability are performance and legacy. This article describes how native code can be invoked from OCaml programs using both the conventional OCaml approach of writing stub functions in C and also a new approach using LLVM to generate the necessary interface code at run-time..."

  28. Metaprogramming with MetaOCaml (27th July 2008)

    "Metaprogramming is a term used to describe programs that generate or manipulate other programs. The ML family of languages were bred specifically for this purpose and, indeed, that is where their name MetaLanguage is derived from. Run-time compilation and execution of programs is a notable feature once present in Lisp as EVAL but sacrificed in the design of ML. The MetaOCaml language is a prototype OCaml derivative that is designed to bring statically-typed metaprogramming to the OCaml family of languages. This article examines the use of MetaOCaml for metaprogramming including some of the practical applications of this technology and the challenges faced by users of this technology..."

  29. Fork-based Parallelism (10th August 2008)

    "As the world transitions to multicore desktop computers over the next few years it is essential that software evolves to take advantage of this new dimension in processing power by exposing parallelism. Although the current OCaml implementation has a serial run-time that limits multithreaded OCaml programs to serial concurrency, it is actually entirely possible to use separate processes to create parallel OCaml programs that do exploit multicores. This article examines a simple but powerful approach to parallelism using Unix process forking..."

  30. Writing a bytecode compiler using LLVM (27th August 2008)

    "The Low-Level Virtual Machine (LLVM) provides the machinery to generate high-performance native code programmatically and on-demand. One of the most important applications of this technology is the Just In Time (JIT) compilation of bytecode intermediate representations into native code, as found in Sun's Java Virtual Machine (JVM) and Microsoft's Common Language Runtime (CLR). This article describes how a simple bytecode interpreter can be developed into a JIT compiler using LLVM with relatively little effort..."

  31. Building a 2D vector graphics library (10th September 2008)

    "Vector graphics represent images in terms of lines and curves on a fictional canvas. This resolution-independent representation is ideal for high resolution output devices such as printers but the inevitable march of technology has ossified vector graphics on the desktop as a fundamental component of both Apple's and Microsoft's latest operating systems. This article describes the design and implementation of a simple library for 2D vector graphics written in OCaml and using OpenGL for visualization..."

  32. Concurrent web crawling (23rd September 2008)

    "Web-enabled technology is now ubiquitous and of huge commercial value. These kinds of programs share two common characteristics: they send information over the internet and they perform tasks concurrently. This article is the first in a series to examine the use of the OCaml programming language and its relatives in the growing area of concurrent web programming..."

  33. Triangulated Irregular Networks (TINs) (11th October 2008)

    "Adaptive subdivision is a hot topic in computer graphics and forms the foundation of many state-of-the-art algorithms for large scale visualization used for everything from scientific visualization of huge data sets to game graphics that immerse players in expansive virtual worlds. This article describes one of the most popular approaches for the adaptive subdivision of 3D meshes and implements a capable plotting algorithm with real-time OpenGL-based visualization showcasing how this simple algorithm works and can be used to solve many different problems..."

  34. Low-level optimization tips and tricks: part 1 (23rd October 2008)

    "The OCaml programming language is unusually well suited to high-performance computing among functional programming languages because it provides a highly efficient code generator with a performant run-time and garbage collector. This makes it feasible to write high performance programs entirely in OCaml without having to drop to lower-level languages like C and Fortran for performance-critical sections of code. This article describes the low-level optimizations that underpin the ability to write performant OCaml programs by leveraging knowledge about the OCaml compiler..."

  35. Huffman data compression (10th November 2008)

    "Data compression algorithms are not only very useful in practice but are also extremely compelling pragmatic examples of programming theory. The popular Huffman data compression algorithm is from the family of entropy encoding compression algorithms. This article walks through the construction of a simple but efficient Huffman compression and decompressor written entirely in OCaml..."

  36. Object-oriented programming in OCaml (23rd November 2008)

    "The OCaml programming language is unique among member of the ML family because it provides not only the core ML features of variant types, pattern matching and functors but also two different features of the type system that provide subtyping: objects and polymorphic variants. Compared to conventional object-oriented languages, OCaml's objects are unusual because they are structurally typed, a characteristic that removed the need to declare class types but which can adversely affect developer productivity and run-time efficiency if used inappropriately. This article describes the design, implementation and use of OCaml's object system, giving references to examples of good design..."

  37. Working with Regular Expressions (10th November 2008)

    "Regular expressions are a domain-specific language for pattern matching over sequences of characters. This functionality provides a concise and efficient way to dissect strings and, consequently, is used in many forms of string processing including the definition of lexers. This article describes OCaml's built-in support for regular expressions..."

  38. Low-level optimization tips and tricks: part 2 (23rd December 2008)

    "The OCaml programming language is unusually well suited to high-performance computing among functional programming languages because it provides a highly efficient code generator with a performant run-time and garbage collector. This makes it feasible to write high performance programs entirely in OCaml without having to drop to lower-level languages like C and Fortran for performance-critical sections of code. This article covers allocation and garbage collection and various forms of specialization including type, function and data structure specialization..."

  39. Solving the Traveling Salesman problem using Simulated Annealing (10th January 2009)

    "Finding global minima of an arbitrary function is a significantly more challenging problem than local function minimization and has many practical applications from the simulation of molecules to the design of printed circuit board layouts. Several different global function minimization algorithms exist, many of which make repeated use of local function-minimization algorithms. This article describes a simple and elegant solution to the traveling salesman problem that uses the simulated annealing approach to global function minimization. The results are visualized in real time using OpenGL. In particular, we use an efficient purely functional data structure to represent the path..."

  40. Building a Virtual Machine using LLVM: part 1 (23rd January 2009)

    "This article is the first in a series examining the design and construction of a simple high-level virtual machine (HLVM) written in OCaml and building upon LLVM. Despite its simple design, the HLVM offers excellent performance, rich run-time types with reflection, tail calls, accurate garbage collection and an easy-to-use C-compatible Foreign Function Interface (FFI). This article describes the first step in construction: JIT compilation of programs from a minimal language..."

  41. Simulating smoke in real-time using fluid dynamics (10th February 2009)

    "In scientific computing, the task of simulating fluid flow accurately by solving the Navier-Stokes equation is notoriously difficult. However, it is possible to compute numerical approximations quickly enough that fluids dynamics may be simulated in real time. This article describes a simple fluid dynamics simulator that uses OpenGL to visualize the results in real time..."

  42. Building a Virtual Machine using LLVM: part 2 (23rd February 2009)

    "This is the second article in the series about our high-level virtual machine (HLVM) project. This article builds upon the foundations laid in the first article to create a much more practically useful language implementation by adding tail call elimination, first-class structs, a foreign function interface (FFI) and first-class function pointers..."

  43. Low-level optimization tips and tricks: part 3 (8th March 2009)

    "The OCaml programming language is unusually well suited to high-performance computing among functional programming languages because it provides a highly efficient code generator with a performant run-time and garbage collector. This makes it feasible to write high performance programs entirely in OCaml without having to drop to lower-level languages like C and Fortran for performance-critical sections of code. This article gives a case study that covers many of the techniques described so far before describing how the performance of the FFI can be improved and some optimizations that often provide substantial performance improvements in OCaml..."

  44. Building a Virtual Machine with LLVM: part 3 (23rd March 2009)

    "This is the third and final article in the series about the design and construction of the high-level virtual machine (HLVM). This article describes the design and implementation of boxed values for sum types and a simple garbage collector. In particular, the difference between the run-time representations of values in OCaml and HLVM is described in detail and the GC implementation described is partially generated at run-time and JIT compiled..."

  45. Emergent behaviour: flocking boids (8th April 2009)

    "Artificial life became a popular topic in the 1980s. In particular, with the discovery that simple rules defining the behaviour of individuals could give rise to sophisticated behaviour of groups of individuals. This unexpected result was described as "emergent behaviour" and one of the most famous examples was a computer program called "Boids" that used only three simple rules to govern the dynamics of individuals but produced remarkably realistic flocking behaviour of the population as a whole. This article describes an interactive boids simulator with a graphical user interface implemented using GTK+..."

  46. Purely functional data structures: streams, queues and catenable lists (23rd April 2009)

    "This article is the first in a series describing the design and implementation of some very useful purely functional data structures. Lazy streams, batched and real-time queues and lists with O(1) concatenation are described in detail. In particular, functors are used extensively to provide elegant parameterization over data structures and some of the new features in OCaml 3.11 are used to improve both performance and clarity..."

  47. Lempel-Ziv-Welch data compression (8th May 2009)

    "LZW is a simple and effective dictionary-based data compression algorithm originally published in 1984 and subsequently used in several prominent places including the GIF image format. This article describes simple purely functional implementations of the compression and corresponding decompression algorithms before examining the optimization of these implementations via the selective inclusion of mutable data structures..."

  48. Pretty printing with the Format module and camlp4 stream parsers (23rd May 2009)

    "The OCaml programming language has evolved a rich variety of libraries and tools over the past twelve years. The domain of metaprogramming is particularly well supplied. This article describes the basic design of OCaml's Format module which provides customizable formatting and, in particular, user-extensible pretty printing for the top-level as well as the stream parsers provided by camlp4..."

  49. Visualizing the Singular Value Decomposition (8th June 2009)

    "Singular Value Decomposition (SVD) is an important algorithm from linear algebra that decomposes a matrix into the product of three simpler matrices. The resulting decomposition has several applications. This article describes the design and implementation of an OCaml program that computes the SVD of an image and uses it to create a lossy compression algorithm with controllable quality. This involves numerical methods for computing the eigenvalues of real symmetric matrices and interactive visualization of the result as a GTK application using the camlimages library to load images from file..."

  50. Compiler development: part 1 (23rd June 2009)

    "This article is the first in a series describing the design and implementation of a complete compiler for a non-trivial language using the freely-available HLVM project described in previous articles. The representation of types, patterns and expressions, the lexer, parser and Read-Evaluate-Print-Loop (REPL) with JIT compilation are described in this article..."

  51. QR decomposition: a case study in profiling and optimization (10th July 2009)

    "The challenge of finding the least squares best fit of a linear sum of functions is a common problem in regression. Linear algebra provides a powerful and general solution by expressing this problem in terms of matrices and then computing the QR decomposition in order to solve the matrix equation. This article describes a remarkably simple implementation of QR decomposition in OCaml and uses it as a case study for profiling and optimization..."

  52. Optimizing the Burrows-Wheeler Transform (23rd July 2009)

    "The Burrows-Wheeler Transform (BWT) is one of the few preconditioners used in data compression and, in particular, is the core of the popular bzip2 compression utility. This article describes a simple 19-line implementation of the BWT in OCaml and progressively optimizes the implementation to use a customized quicksort then distributed fork-based parallelism and finally shared-memory parallelism. On 8 cores, the final optimized implementation is over 65× faster than the original..."

  53. Dynamic programming: Levenshtein edit distance (8th August 2009)

    "Levenshtein distance is a metric used to measure the amount of difference between a pair of sequences in terms of the number of insertions, deletions and substitutions required to get from one sequence to the other. Computing the Levenshtein distance is an interesting problem in dynamic programming with many practical applications including spell checkers and the study of DNA in bioinformatics. This article describes how the basic algorithm may be implemented and then optimized, including the use of both generic and specialized memoization..."

  54. Traversing networks: the nth-nearest neighbor (23rd August 2009)

    "Graph theory has a great many practical applications ranging from compiler internals to the study of the structural characteristics of materials. This article describes the design and implementation of a program that finds the nth-nearest neighbors of a given vertex in an infinite graph. This problem is of interest in the context of atomic structures..."

  55. Stanford Bunny (8th September 2009)

    "The Stanford bunny is a 3D mesh of triangles commonly used as a benchmark for computer graphics applications. This web page presents an 85-line OCaml program that uses OpenGL to render the Stanford bunny in real time: the mesh is represented as a vertex array and an index array. The vertex array is a sequence of 3D vertex coordinates. The index array is a sequence of triples of indices into the vertex array referring to the three vertices of each triangle. Normals are generated independently for each vertex as the sum of the normals of every triangular face sharing each vertex, in order to provide smooth shading..."

  56. The Graphics module: Pythagoras Tree (23rd September 2009)

    "The OCaml distribution includes a Graphics module that provides a set of easy-to-use portable drawing primitives ideal for educational purposes and experimentation. This article describes the recursive construction of some digital art built around Pythagoras' triangle. The results are visualized interactively using the Graphics module..."

  57. OCaml4Multicore (oc4mc) (10th October 2009)

    "OCaml4Multicore is a modified OCaml compiler that allows POSIX threads to run in parallel. This is a major development that makes shared-memory parallel programming much easier and also has the potential to make it far more efficient for many important appications. This article introduces the subject of thread-based parallel programming, explains why it is difficult to facilitate in OCaml-like language implementations and examines the performance characteristics of oc4mc..."

  58. LLVM 2.6 support and a new HLVM garbage collector (23rd October 2009)

    "This article describes the changes required to bring HLVM up to date with respect to the new LLVM 2.6 release as well as a new garbage collector design. The previous collector mapped pointers onto their mark state via a hash table. This update uses the more conventional design of placing the mark state in the heap, using a mark-sweep garbage collector to reclaim unreachable values. The new collector is simpler and offers different performance characteristics..."

  59. Logic programming: n-queens and knight's tour problems (8th November 2009)

    "Logic programming is a paradigm often seen in problem solving and AI. This article introduces the subject of logic programming and explains why the OCaml language and implementation are ideally suited to these kinds of applications, using the familiar examples of solving the n-queens problem and finding a knights tour..."

  60. Generating and visualizing 2D mazes (23rd November 2009)

    "Maze generation is a remarkably complex and diverse subject that essentially falls into the category of network or graph theory but is most often seen in the context of games and puzzles. The characteristics that make a maze interesting for humans to try to navigate are subjective and not easily defined and, consequently, the design and implementation of an automatic maze generator is as much an art as it is a science. This article describes the design and implementation of a simple but effective maze generation algorithm including OpenGL-based visualization. The algorithm is elegantly expressed in terms of recursive functions and purely functional data structures..."

  61. Parsing and visualizing binary Geographic Information System data (8th December 2009)

    "Detailed vector descriptions of worldwide geographical data are freely available in the Shapefile format. This article describes how polygonal data can be parsed from the binary Shapefile format and visualized using OpenGL and GLU easily and efficiently with OCaml. The result is a simple program that can be used as the basis for a wide variety of Geographic Information System (GIS) applications from cartography to climatology..."

  62. Garbage collecting multithreaded programs (23rd December 2009)

    "Executing threads in parallel is the cornerstone of efficient parallel programming on shared-memory machines including today's multicores. This article describes how a simple stop-the-world garbage collector can be implemented in HLVM, allowing code generated from an OCaml program to leverage multicores easily..."

  63. Low-level optimization tips and tricks: part 4 (8th January 2010)

    "The OCaml programming language is unusually well suited to high-performance computing among functional programming languages because it provides a highly efficient code generator with a performant run-time and garbage collector. This makes it feasible to write high performance programs entirely in OCaml without having to drop to lower-level languages like C and Fortran for performance-critical sections of code. This article focuses on the internal representation of data structures. An overview of OCaml's data representation strategy is given. Tools to examine values in the heap, including OCaml's own Obj module, are described. Then several approaches to optimization that are related to data representations are covered, including closures, polymorphic variants, bounds checking, functors and integer arithmetic..."

  64. High-performance parallel programming with HLVM (23rd January 2010)

    "This article describes how a global adjustment of the calling convention brings the performance of the multicore-capable HLVM within 17% of its original single-threaded performance. A simple parallelization of the new ray tracer benchmark is then described that obtains a substantial 6.3× speedup on 8 cores, demonstrating the potential of the new design for high-performance parallel computing..."

  65. Force-based network visualization (8th Febuary 2010)

    "Visualizing a graph or network of interconnected nodes is a fascinating and important challenge with a wide variety of practical applications. This article looks at a simple but effective force-based approach to the visualization of networks and uses OpenGL to display the results in real-time as they emerge and GTK+ to provide interactive user control. The result is a compelling interactive animation of the layout algorithm as it progresses..."

  66. Implementing Hindley-Milner type inference (23rd Febuary 2010)

    "This article walks through the design and implementation of the Hindley-Milner type inference algorithm written in OCaml. This algorithm is the foundation of type inference most modern functional programming languages including OCaml. The algorithm acts upon expressions and types using type scheme, substitutions and type environments to infer the type of a given expression..."

  67. Word games (8th March 2010)

    "String manipulation is a common task in programming and, in particular, when scripting. Solving word puzzles is an excellent way to learn how these kinds of problems can be approached. This article uses the example of word games to develop a series of programs that manipulate strings using different techniques in OCaml, including sorting and searching..."

  68. Compiler development: part 2 (23rd March 2010)

    "This article is the second in a series describing the design and implementation of a complete compiler using the freely-available HLVM project described in previous articles. This article extends the compiler implemented in part 1 of the series with support for variant types and basic pattern matching. This requires changes to the representation of the compiler's input, the lexer, the parser, the compiler and the REPL. The language implemented by the resulting compiler is substantially more expressive than the previous version and allows monomorphic ML-style programs to be compiled and executed..."

  69. The A* algorithm (8th April 2010)

    "The A* algorithm is often used for route finding in game AI and is a generalization of Dijkstra's shortest-path algorithm from graph theory. This article describes a simple implementation of the A* algorithm written in OCaml that makes extensive use of the module system including higher-order modules (functors) in order to provide a reusable implementation of this algorithm that is generic over the kinds of graphs that it can handle. Finally, an example application is provided that finds a route around a hill..."

  70. Compiler development: part 3 (23rd April 2010)

    "This article continues our series on compiler development using HLVM. An example is provided that breaks the current compiler. The bug is investigated using different techniques and a well-known solution is implemented. The resulting compiler is then tested on a substantially more complicated symbolic computation and is found to obtain the correct result. Moreover, the time taken to perform this symbolic computation using HLVM is found to be very competitive despite the fact that HLVM was not at all designed for this purpose..."

  71. Artificial Intelligence: Neural Networks (8th May 2010)

    "Artificial neural networks are a relatively simple and early form of artificial intelligence modelled directly on the structure of an organic brain. A neural network is composed of many interconnected neurons. Each neuron acts as a simple linear classifier by summing its weighted inputs and firing an output accordingly. The functions involved are essentially ad-hoc but are usually modelled on those of real neurons. This article describes the design and implementation of a neural network that uses an unconventional functional approach to handle vector-matrix operations that allows temporary data structures to be avoided..."

  72. Sliding Median (23rd May 2010)

    "Sliding window algorithms are a class of algorithms that treat streams of data by computing a statistic across a window for each position of the window within the data stream. Moving averages are sliding window algorithms that compute an average over each window. This article examines the moving median algorithm that tracks the median value in a window as it slides across a stream of data. Several possible solutions are examined and their performance is studied on an example data set..."

  73. Visualizing the 2D Fourier Transform (8th June 2010)

    "The Fourier transform is one of the most important numerical methods and underpins most forms of spectral analysis. This article describes a simple image compression technique that uses the 2D Fast Fourier Transform (FFT) to remove the high-frequency components of an image, visualizing the result using GTK..."

  74. Quicksort (23rd June 2010)

    "The quicksort algorithm was invented by Tony Hoare in 1960 and remains one of the most celebrated algorithms and is still of great practical value. Implementing some of the many variations of the quicksort algorithm serves as an excellent introduction to programming in OCaml..."

  75. The diff tool (8th July 2010)

    "The unix program diff identifies differences between text files, line by line. This tool is most useful for comparing two versions of a program. This article develops a simple implementation of the diff tool based upon the longest common subsequence (LCS) algorithm and examines the output from it..."

  76. Rigid body dynamics (23rd July 2010)

    "A common technique to simulate the dynamics of objects is to model them as interacting rigid components. This article describes the design and implementation of a simple OCaml program that uses rigid body dynamics to simulate balls bouncing around in 2D, using OpenGL for 2D visualization..."

To receive notifications as new articles are published, please subscribe to our OCaml News blog feed available from this page.

(Note: We are not VAT registered and, therefore, cannot provide VAT receipts)

Mastercard VISA VISA Delta VISA Electron VISA Purchasing JCB Solo Switch