Thursday, 11 December 2008

Working with Regular Expressions

The OCaml Journal just published an article about regular expression for string manipulation:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Wednesday, 26 November 2008

LLVM 2.4 released

Developers of the compiler framework LLVM are sticking to a rapid release schedule, shipping the latest 2.4 version of LLVM. This includes extensive OCaml bindings that can be used to generate arbitrary native code at run time.

OCaml and LLVM form a powerful team that can be of mutual benefit in many different ways. Firstly, the OCaml language is derived from a family of languages that were specifically designed for manipulating programs and writing compilers. So OCaml is ideally suited for this task and many LLVM users stand to gain a lot by writing their high-level code (particularly front-ends) in OCaml. Secondly, the current OCaml implementation can be improved in many different ways using LLVM. One alluring project is the creation of an automated FFI for OCaml that uses run-time generated code to interface to existing native code libraries with a minimum of fuss by eliminating the impedance mismatch between the OCaml and C type systems and representations.

Using LLVM from OCaml has been the topic of two OCaml Journal articles already this year.

Monday, 24 November 2008

Object-oriented programming in OCaml

The OCaml Journal just published an article about object oriented programming:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Stunning slides about the growth of OCaml at XenSource/Citrix

In 2002, members of Cambridge University released the open source Xen project to provide free high-performance virtualization technology for the masses.

In 2004, the team founded the company XenSource and began developing the enterprise-level distributed management software that would make virtualization easy and form the backbone of their products in the years to come. A team of thirty dedicated programmers in Palo Alto California began developing the software in C, Python and Ruby.

Two years later, the US team had succeeded in burning tens of millions of dollars funding but had failed to produce any product. So XenSource, under new management, took the bold step of replacing their large team of US developers with a team of only four British OCaml developers. Within months, all of the Python and Ruby was replaced, both reliability and performance were dramatically improved and the company shipped their first product. One year later, XenSource sold to Citrix for $500M.

One of the first OCaml developers to join XenSource, Anil Madhavapeddy, stunned the audience at this years CUFP conference with the tale of Citrix growing from 4 to 18 OCaml developers since April 2006. Anil has kindly made his awe-inspiring slides available on-line.

Monday, 10 November 2008

Huffman data compression

The OCaml Journal just published an article about data compression:

"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 compressor and decompressor written entirely in OCaml..."

To read this article and more, subscribe to The OCaml Journal today!

Sunday, 2 November 2008

Low-level optimization tips and tricks: part 1

The OCaml Journal just published an article about optimization:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Saturday, 1 November 2008

Largest order of OCaml for Scientists

Cornell University recently placed the largest ever order of our book OCaml for Scientists in order to use our monograph as a text book for their students when teaching the awesome OCaml programming language. To date, OCaml for Scientists has sold hundreds of copies worldwide and continues to be one of our best selling products, having earned us 4.5× more profit than the average programming book.

If you would like to place a bulk order of OCaml for Scientists, please contact us.

Saturday, 11 October 2008

Triangulated Irregular Networks (TINs)

The OCaml Journal just published an article about computer graphics:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Wednesday, 8 October 2008

Oberon-2 compiler written in 6kLOC of OCaml

Mike Spivey from the Computer Lab at Oxford University hosts the Oxford Oberon-2 compiler, which is written in OCaml with C for the Boehm-based run-time. The source code to the compiler is recommended reading for budding compiler writers using MLs such as OCaml.

Thursday, 25 September 2008

Concurrent web crawling

The OCaml Journal just published an article about concurrent web programming:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Friday, 12 September 2008

Building a 2D vector graphics library

The OCaml Journal just published an article about vector graphics:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Wednesday, 10 September 2008

LLVM tutorials ported to OCaml

Erick Tryzelaar has done a fantastic job translating the LLVM tutorials from C++ to OCaml. The fruits of his labor are available here.

This tutorial describes the implementation of a compiler for the "Kaleidoscope" language including lexing, parsing, basic code generation using LLVM, JIT compilation using LLVM and the introduction of control flow and mutable variables.

LLVM is one of the world's most exciting open source projects and the early development of comprehensive OCaml bindings to LLVM has fuelled a great deal of cross-pollination.

Monday, 8 September 2008

Year long subscriptions to the OCaml Journal!

Due to popular demand we have introduced year-long subscriptions to The OCaml Journal. Subscribers taking out 1 year subscriptions to both The OCaml Journal and The F#.NET Journal at the same time can currently benefit from a 25% discount!

Friday, 5 September 2008

OCaml on eight cores

In preparation for OCaml's forthcoming parallel garbage collector, Flying Frog Consultancy have invested in an eight core computer. The machine is a Dell PowerEdge T605 with eight AMD Opteron cores and 4Gb of RAM.

Unable to resist temptation, we immediately reran the parallel ray tracer from the OCaml Journal article Fork-based parallelism and obtained near-optimal speedup when using all eight cores:

Watch this space for more parallel benchmarks using OCaml!

Writing a bytecode compiler using LLVM

The OCaml Journal just published an article about the compilation of bytecodes:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Friday, 29 August 2008

OCaml for Scientists now at least as cheap as ever!

Many readers will already know that the OCaml programming language is widely used in the finance industry. What many people do not know is that workers in the finance industry often live on the bread line and, consequently, they have no choice but to find ways to obtain essential items cost effectively.

This appears to have been the case for our famous OCaml for Scientists book, which has seen its price slashed from US$170 to only US$155 in recent weeks thanks to some ingenious gambles made by workers in the finance industry helping to drive down the prices of essential European goods. Everyone in the US and other countries (like Canada) can now benefit from a cheaper but equally comprehensive OCaml for Scientists.

Tuesday, 12 August 2008

Fork-based Parallelism

The OCaml Journal just published an article about parallel programming:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Monday, 28 July 2008

Growth of the OCaml job market

Functional programming languages have been around for a long time, of course, but they have only very recently begun to be adopted for more mainstream programming tasks. This is reflected in the job market and the IT Jobs Watch website does an excellent job of trending job market trends over time for different programming languages, including OCaml. The results are nothing short of miraculous:

This shows that, at least in the UK, the OCaml job market is growing at an incredible rate: 12× as many OCaml jobs on the market as last year.

Moreover, the range of salaries for OCaml developers is substantially higher than all mainstream languages: £45-68k compared to only £38-45k for C# and £42-52k for Java. As we predicted last year, this trend is driven by employers using programming language diversity as a way to identify superior candidates and this trend is driving more and more young developers to better their programming abilities and job prospects by learning advanced languages like OCaml.

We believe this trend will continue for several years to come.

Sunday, 27 July 2008

Metaprogramming with MetaOCaml

The OCaml Journal just published an article about MetaOCaml:

"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 transition to 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..."

To read this article and more, subscribe to The OCaml Journal today!

Saturday, 12 July 2008

Calling C code from OCaml

The OCaml Journal just published an article about OCaml's foreign function interface:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Tuesday, 24 June 2008

Tricks with recursion: knots, modules and polymorphism

The OCaml Journal just published an article about recursive type and function definitions:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Friday, 13 June 2008

Real-time Finite Element Materials simulation

The OCaml Journal just published an article about real-time simulation:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Monday, 26 May 2008

Implementing a simple XML-RPC client and server

The OCaml Journal just published an article explaining how both producers and consumers of remote procedure calls can be written in OCaml:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Monday, 12 May 2008

Porting and optimizing the SciMark2 benchmark

The OCaml Journal just published an article about the SciMark2 benchmark:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Monday, 28 April 2008

Language oriented programming: Term Rewriting

The OCaml Journal just published an article describing term rewriting:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

OCaml to get Concurrent Garbage Collection

Following our exploits with Microsoft's F# programming language, which inherits a concurrent garbage collector from their excellent common-language run-time (CLR) implementation, we have been wondering if OCaml would ever acquire a concurrent GC of its own. Concurrent garbage collection is tremendously useful in a wide variety of circumstances and is of increasing importance as the world transitions to multicore CPUs for desktop computers. Compared to OCaml, concurrency in F# makes it much easier to spawn interactive visualizations from the top-level, write high performance parallel numerical codes and keep GUI applications fluid.

The developers of OCaml at INRIA in France, led by Xavier Leroy, have long since given up on developing their own concurrent GC for OCaml, famously stating in 2002 that developing their own concurrent GC was "Too complex" and "too hard to debug".

Fortunately, Jane St. Capital (one of the largest industrial users of OCaml) have chosen to fund a "multicore" summer project that aims to provide a basic concurrent garbage collector implementation for OCaml. The team from the Université Pierre et Marie Curie, led by Emmanuel Chailloux, intend to complete this project during the summer of 2008.

We have already written to team to suggest that they might also make their run-time compatible with the excellent LLVM project because this would make it much easier for open source developers to reuse this exciting technology.

Friday, 11 April 2008

Labeled and Optional arguments

The OCaml Journal just published an article describing the use of labeled and optional function arguments:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Friday, 28 March 2008

Nice ray tracer in OCaml

The Bla Repository just posted an interesting ray tracer example, written entirely in OCaml.

Thursday, 27 March 2008

Getting the most out of Static Typing

The OCaml Journal just published an article explaining how OCaml's static type system can be leveraged to improve program reliability and development speed:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Sunday, 9 March 2008

Run-time compilation with LLVM

The OCaml Journal just published an article describing basic use of the LLVM library:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Saturday, 1 March 2008

Book Review: OCaml for Scientists

Fabrice Marchant has kindly written and published the following review (also available in French) of the book OCaml for Scientists:

"I have read OCaml for Scientists, the work of Dr Jon Harrop, which is dedicated to the OCaml programming language. Even though science and technical computing are inherent aspects of this book this is not restrictive with the exception of a few complicated examples in the final chapter.

The OCaml language combines functional and imperative programming. It is very fast and has garbage collection. Type inference makes coding particularly concise, safe and easy. OCaml's embedded module language and object orientation form a powerful software engineering tool.

Without requiring knowledge of ML-type languages, OCaml for Scientists teaches the reader how to use OCaml for scientific computing, including the use of several powerful libraries among the examples.

There are few prerequisites for correctly following the book because the author introduces the classical concepts of programming (such as recursion) before progressively developing.

That being said, the knowledge of an imperative programming language (like C or Pascal) or a functional one (such as Lisp or Scheme) is not absolutely required but would make the book more straightforward.

An important part, at the beginning of the book, is dedicated to a proper understanding of the language itself: here one finds coverage of the functionalities offered by OCaml's many keywords, illustrated by numerous clear examples.

This book does not content itself with being only a tutorial of the language. The author shows the proper usage of the possibilities of OCaml - such as the best programming practices - and often goes further in justifying things by studying the internal representation used by the compiler.

Working side-by-side with practical examples, the clarity of the exposition of this part of the book constitutes what is probably one of the most efficient mediums offered to the beginner, to rapidly acquire an understanding of the basic language necessary to program.

Dr Harrop teaches things in such a manner that reading is always easy, even when covering non-trivial scientific subjects. The syntactic coloration, on large white pages, makes the book pleasant to open.

These two aspects work together to give an impression of clarity and simplicity.

The book, stuffed with examples, has a practical view of the different programming components comprising the OCaml system: The customisable top-level, the many compilers, the dependency visualiser and profiler, are all presented together with their usage.

The book's examples are worth a special mention. With the exception of the contents page, it is difficult to find a page which does not present several concrete examples of programming. Some of them are surprisingly elaborate.

Similarly, on the practical side: The use of certain libraries, such as "command line arguments, big arrays, vector matrix and lexing and parsing, are presented in detail.

Despite the scientific focus, the first few chapters are of general interest.
Other parts such as visualisation (with OpenGL) or lexing and parsing, are perhaps particularly useful for game designers.

In addition to OCaml for Scientists, I own "Programmation fonctionnelle, générique et objet (Une introduction avec le langage OCaml)" by Philippe Narbel. The two works complement each other, OCaml for Scientists being more concrete. To cite only the unique parts of OCaml for Scientists, it presents libraries and studies optimisation in detail.

Certainly, IMHO, a section detailing the writing of functors would have been welcome. However, studying the book gives an understanding of the language such that one can undertake substantial programming projects.

The book, preceded by a glossary, is divided into ten thick chapters:

Introduction, Program Structure, Data Structures, Numérical Analysis, Input and Output, Visualization, Optimization, Libraries, Simple Examples and Complete Examples, Bibliography, Advanced Topics and Troubleshouting.

To conclude, OCaml for Scientists is an excellent book, clear and practical, which can be used as a reference work."

Tuesday, 26 February 2008

High-fidelity graphics with OpenGL 2

The OCaml Journal just published an article describing how GLSL shaders can be used in OCaml programs using the new GLCaml bindings to OpenGL 2:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Wednesday, 20 February 2008

GLCaml 20080215

Following our GLCaml fix, Elliott Oti has shipped a new GLCaml with extensive bug fixes as well as lots of API improvements. In particular, these are the first working OpenGL 2 bindings for OCaml , including support for GLSL shaders.

Hopefully this will usher in a new era of visualization software written in OCaml.

Monday, 11 February 2008

Language-oriented programming: The Term-level Interpreter

The OCaml Journal just published an article that walks through the construction of a simple term-level interpreter for a new programming language:

"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...."

To read this article and more, subscribe to The OCaml Journal today!

Thursday, 24 January 2008

Factoring numerical methods using combinators and functors

The OCaml Journal just published an article demonstrating how functional constructs can be invaluable when implementing numerical methods:

"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..."

To read this article and more, subscribe to The OCaml Journal today!

Friday, 11 January 2008

Implementing a simple Ray Tracer

The OCaml Journal just published an article describing the design and implementation of a simple ray tracer with real-time incremental visualization in a GUI using OpenGL and GTK+:

"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..."

To read this article and more, subscribe to The OCaml Journal today!