Friday, 16 February 2007

Benefits of pattern matching

Modern functional programming languages like OCaml provide many beneficial features not found in older languages like Lisp. ML-style pattern matching is one such feature that is heavily used by OCaml programmers both because it is fundamental to the language and because it is useful in many different situations.

In a recent thread on comp.lang.functional entitled "ML vs. Lisp", Paul Rubin asked what a Lisp programmer learning ML should focus on. I suggested pattern matching as one of the more important topics, giving the example of OCaml functions to simplify symbolic expressions: