Published on 11th June, 2024

I am Learning ML but not Machine Learning

ML - Meta Language

Is it crazy how if you search ML on the internet or Youtube you hit only resources on Machine Learning. Machine Learning has shadowed Meta Language, the Programming Language. You would only have better luck if you searched Standard ML, which is a modern dialect of ML.

So why am I learning an obscure ancient programming language? ML is one the most popular Programming Languages that you have never heard of. No, I am not selling you snake oil, it is not like you would buy with bitcoin anyway.

Before the decision to learn ML, I had already wanted to learn OCaml. I am a huge fan of programming languages, there is a whole page in this blog where I have listed the languages that I have learnt and I wish to learn. The to learn list will keep on growing. Worth noting is that even though I love languages,I am not interesting in FOMOing to learn the the newest and shiniest languages. There are definitely new languages, that have caught my attention though. I love old school languages. Why? If you read a little about Programming Languages, you will realize that at one point we created particular languages that were so full of good ideas that most languages that came after them copied a thing or two. In my mind if you study a language that had good ideas that 10 modern languages copied ideas from, it is like learning 1 and getting 10 free. Not exactly, but you get the idea.

While studying Crafting Interpreters, in page 65 while talking about The Expression Problem, Bob. said that


"ML, short for 'metalanguage' was created by Robin Milner and friends and forms one of the main branches in the great programming language family tree. Its children include SML, Caml, OCaml, Haskell, and F#. Even Scala, Rust, and Swift bear a strong resemblance. Much like Lisp, it is one of those languages that is so full of good ideas that language designers today are still rediscovering them over forty years later."


Who wouldn't want to learn a language that had so many novel ideas in language design that over 40 years later, other Programming Language designers are still taking ideas from? Well actually not a lot of people, first you probably have to be a programmer, but not me. That is ML. At this point I would probably say I am language designer sort of and I could make good use of some ideas. One syntax that I found that I thought was pretty need is how you can use #struct_item_name StructName; to get the value of a struct item, borrowing from Rust terminology but in ML we call them Records.

  
  ML
  ------
  val Rust = {
    creator = "Graydon Hoare",
    company = "Mozilla",
    release = 2015,
    quote = "Rust's raison d'etre is safety"
  };

  #creator Rust;
  (* This is weird and neat to me lol *)

  Rust
  ------
  struct Rust {
    creator: String,
    username: String,
    email: String,
    quote: String,
  }

  let language = Rust {
    creator: String::from("Graydon Hoare"),
    company: String::from("Mozilla"),
    release: 2015,
    quote: String::from("Rust's Raison de'tre is safety")
  };

  language.creator;
  

When I wanted to learn OCaml, it was because I read somewhere that OCaml was used to write the first Rust Compiler. That combined with the fact that it is a functional programming language got me interested enough, to want to learn it. And OCaml, more like Caml, SML, Elm are all coming from ML. And you can add Roc, which I am hoping to start contributing to its development.

Most Programming Languages we use today stem from a few languages, ML is one of those Languages, another is ALGOL.

That means, even though you might not have heard of ML or given it a second thought, you might just be using ML, in your favorite language without knowing, because at some point of the design of that language, its designers decided to go with a language feature that was pioneered by ML.

So Why Meta Language ?

I can't make a better write up to this question than what the wikipedia article has so I will just leave a link here. But stick around to read why I find it worth reading, this is my just my opinion, wildly based on my curiosity.

"While working on the theorem proving system LCF (short for Logic of Computable Functions), Robin Milner and colleagues in the early 1970s created a language for writing scripts to create proofs. Since LCF was itself a language for representing formulas in an underlying logic, the theorem proving language was called the Meta Language, or ML for short. The original ML language soon evolved into a general-purpose programming language. Like Lisp, it featured first-class functions and pattern matching, and was expression-oriented and garbage-collected. Unlike Lisp, ML was statically typed, and was the first language to implement the Hindley-Milner type system and its associated type inference mechanism." - Programming Language Explorations

1. Learn a Functional Programming Language

ML is a general-purpose functional programming language. I did a lot of my of first programming in Python. Even though, I started with C, I learnt a very tiny part of C and learnt JavaScript but I wrote a lot of my code in Python which is a multi-paradigm dynamic programming language it was through Python that I learnt OOP - Object Oriented Programming and using Python to build web applications with the Django web framework meant most of my code was Object Oriented. I am a big believer that the programming language you use influences how you think, it influences how you approach problem solving. And following the advice of Peter Norvig from his amazing article Teach Yourself Programming in Ten Years, I have always wanted to learn a functional programming language. I know about other functional programming languages like Haskell, Elixir, Erlang and many others. I did learn a little Elixir in 2019. I got to know of Erlang through a friend back in 2016, at the time I didn't know the distinction in programming languages paradigms like I do today, but I wanted to learn Erlang because my friend said it was hard. I never learnt it though. Erlang and Elixir are part of the languages to learn, just out of curiosity. But for now, my functional programming language journey is starting from ML.

What did Peter Norvig say?

In the early days when I started learning to code, I was obsessed with becoming a great programmer, and I would be asking the internet here and there, how to become one but when I found his article I stopped searching. I hope that even if you don't find this article interesting, you would love Peter's advice linked above.In one section of the article he said,

"Learn at least a half dozen programming languages. Include one language that emphasizes class abstractions (like Java or C++), one that emphasizes functional abstraction (like Lisp or ML or Haskell), one that supports syntactic abstraction (like Lisp), one that supports declarative specifications (like Prolog or C++ templates), and one that emphasizes parallelism (like Clojure or Go)."


2. The Hindley-Milner type system

ML is the first programming language to implement the Hindley-Milner type system, Which is known for its ability to infer most general types of a program without the programmer needing to explicitly type the type annotations. Think of all the programming languages that have types inference today. I want to explore and learn more of how all those came about. Rust was my first statically typed programming language and I have fallen in love with statically typed programming languages and by extension Type Systems.

While I was learning I hit this error message and I couldn't help but notice how similar the syntax looks to Rust Lifetimes. There are probably several more features in Rust that comes from ML, hopefully, I will write another article as a learn more ML.

  
  {born: int, crowned: 'a, died: int, name: 'b, quote: 'c} -> int
  Here, 'a, 'b, and 'c are type variables that can be any type,
  since they are not used in any operations within the function.
  The fields born and died must be of type int because they are
  used in the subtraction operation.
  

3. Learn 1 get 10 free.

Remember when I said ML is the Most Popular Programming Language you have never heard of? Well take a look at some of the languages that ML influenced.

  • 1. F*
  • 2. Haskell
  • 3. Idris
  • 4. Kotlin
  • 5. Miranda
  • 6. Nemerle
  • 7. OCaml
  • 8. Opa
  • 9. Erlang
  • 10. Rust
  • 11. Scala
  • 12. Standard ML
  • 13. Clojure
  • 14. Coq
  • 15. Cyclone
  • 16. C+,
  • 17. El,
  • 18. F#