Chapter 4Standard MLslides.en.pdf:197

SML: A Pure Functional Language

Programs are expressions; values are immutable

Def 1.1Functional language
Concept

Standard ML (SML) is a pure functional programming language. Per Def 1.1 (slides p.197), a language is functional if every procedure can be fully described by its input/output behavior — no hidden state, no mutable memory.

Three ideas make SML different from languages you may have seen:

  • Programs are expressions. A program is a syntactic expression that the interpreter evaluates to a value. There are no statements that just "do" something without returning a result.
  • Values are immutable. Once a variable is bound to a value, that binding never changes. If you write val x = 3, x is 3 forever (in its scope).
  • Functions are first-class. A function is a value like any other: you can pass it to another function, store it in a variable, or return it from a function call.

Why this matters for AI: symbolic AI manipulates structured representations (parse trees, logical formulas, proofs). Pure functional code makes the structure of data explicit, makes programs easier to reason about formally, and lets the compiler perform aggressive optimizations. The downside — and a feature — is that SML deliberately omits loops, mutable variables, and objects; if you want them, you express them via recursion and higher-order functions.

Worked example
Step 0 of 2
Practice — score 100% to advance
Multiple choice
Q1
What does it mean that SML is a pure functional language (Def 1.1)?
Q2
In SML, what happens when you write val x = 3?
Q3
Which of these is NOT a feature of pure functional programming?
Q4
Why is functional programming well-suited to symbolic AI?
Loading…