Hello World in Standard ML

Our first program will print the classic “hello world” message. Here’s the full source code.

(* hello-world.sml *)
val _ = print "hello world\n"

To run the program, save the code in a file named hello-world.sml and use the SML/NJ (Standard ML of New Jersey) interactive environment to execute it.

$ sml < hello-world.sml
hello world

Alternatively, you could use the interactive REPL (Read-Eval-Print Loop) session provided by the SML/NJ environment to enter the code directly.

$ sml
Standard ML of New Jersey v110.79 [built: Tue Aug 13 18:21:57 2019]
- val _ = print "hello world\n";
hello world
val it = () : unit
- 

Now that we can run and build basic Standard ML programs, let’s learn more about the language.