Last updated: July 5, 2019
ML: Get Started With Metaprogramming
Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more
ML stands for “meta-language,” and ML is a member of the general purpose programming languages family.
Like many early programming languages, ML was created by the academic community for research purposes, and its features influenced many programming languages that followed in its footsteps.
What is ML?
ML is a multi-paradigm, extended functional programming language. It is also often labeled as an “impure” functional language, because it allows side-effects. ML’s imperative features are built on a functional core.
It is particularly useful for meta-programming — writing programs that manipulate other programs, and that is ML’s original purpose. ML is well known for its use of the Hindley-Milner type system that can automatically assign the types of most expressions without explicit type annotations.
ML is used for a wide variety of programming:
- Scientific applications;
- Theorem provers;
- Analyzers, compilers, programming languages;
- Financial systems applications;
- Bioinformatics and genealogical databases.
ML is also used in education, in introductory programming courses to demonstrate basic programming logic and methods.
Brief History of ML
The ML programming language was developed in the 1970s by Robin Milner and his colleagues at the University of Edinburgh during their work on the Logic for Computable Functions (LCF) — an interactive automated theorem prover. LCF was implemented in ML and introduced in 1972. ML’s syntax was inspired by the ISWIM programming language.
ML further evolved into several programming languages, all part of the ML family. The two most important dialects today are Standard ML (SML) and OCaml. Features and ideas from ML influenced many other languages like Cyclone, Elm, Nemerle, Haskell, C++, and others.
This is a strictly typed language, making use of the Hindley-Milner type system to ensure type safety. As a result, a well-typed ML program does not cause runtime type errors. Its syntax and flow control is fundamentally different from C-type languages, so you will not find trivial mapping between C and ML code.
ML features an automatic memory management system through garbage collection, where memory is automatically allocated and freed-up by the compiler. Parametric polymorphism is supported, meaning that you can write a single polymorphic function that can take a parameter of any compatible type.
ML has first class functions and lexical closures, making it very easy to compose multiple functions, a task that can be very complicated in imperative programming languages.
ML also supports polymorphic recursive datatypes with pattern matching, and has an excellent module system centered around
signatures. It primarily uses eager evaluation, meaning that all subexpressions are always evaluated, while lazy evaluation can still be achieved through the use of closures.
Getting Started with ML
If you have previous experience in programming methods and logic, getting started with ML programming should not pose much of a challenge. However, if ML is your first introduction to programming, you should start with basic tutorials and courses, before you move on to more demanding ones.
Your ML Development Environment
You will obviously have to set up your own personal ML development environment. We suggest using the Standard ML of New Jersey (SML/NJ) derivative and compiler, since it is the first and most popular compiler for the ML programming language.
SML/NJ is currently supported on the big three operating systems platforms: Mac OS X, Linux, and Windows. In other words, you should have no trouble running an ML development environment on just about any computer.
ML has been around for years, so there is no shortage of various resources. When it comes to learning the language, this is always a good thing. But keep in mind that many ML resources are quite old and may be outdated.
We focused our search on relevant and relatively recent tutorials, e-books, and interactive courses. However, even old resources can be helpful if you are just getting started.
ML Courses and tutorials
Focusing on theoretical resources is a good way of taking your first steps in ML programming, but once you master the basics, you will need to shift to practical examples.
To truly appreciate the full potential of ML, you will have to see it in action. Once you are comfortable with basic syntax, you can take your training to the next level and try out practical guides and tutorials:
- Programming in Standard ML ’97: An On-line Tutorial by Stephen Gilmore: this is a free ML tutorial introducing important concepts in the ML language and illustrating them with brief examples. It is available in various formats.
- Programming in Standard ML (pdf) by Robert Harper: this is a free ML tutorial created for the Carnegie Mellon University course “Computer Science 12-212: Principles of Programming.”
- A Gentle Introduction to ML by Andrew Cumming: this is a free course containing an introduction and seven lessons on ML with many other useful resources.
- Tips for Computer Scientists on Standard ML (Revised) (pdf) by Mads Tofte: this is a free book, with numerous useful tips on ML programming.
The next step is to focus on more elaborate resources, such as practical tutorials with lots of sample code. These real-life examples will help your understanding of ML programming. We singled out a couple of the most commonly referenced ones:
- Standard ML of New Jersey User’s Guide: this is an online guide to programming in Standard ML using SML/NJ, covering everything from the installation of SML/NJ to FAQ, special features, compiler structure, and libraries.
- The Standard ML Basis Library is an online reference for the Standard ML Basis Library.
We have also included a few books on ML programming. Many of these e-books are recommended by ML educators, and they will come in handy as reference while you are working on practical guides and tutorials:
- ML for the Working Programmer, 2nd Edition by L C Paulson: this focuses on explaining how to program in the ML language, and teaching the fundamentals of functional programming.
- Elements of ML Programming, ML97 Edition (2nd Edition) by Jeffrey D Ullman: this book provides a highly accessible, step-by-step introductory tutorial on ML programming and a complete reference to, and explanation of, advanced features. No previous knowledge of ML or functional programming is required.
- The Little MLer by Felleisen and Friedman: this book introduces those new to programming, as well as those experienced in other programming languages, to the principles of types, computation, and program construction.
As with all programming languages, ML will ultimately be learned by doing. So get your development environment set up, and with the help of these resources, start coding. Good luck!
Learn about other interesting programming languages.