datatype 'a tree = Leaf | Node of 'a tree * 'a * 'a tree This is a free algebra . You can then write functions that pattern-match on the structure, much like defining a function by cases in mathematics.
fun compose (f, g) = fn x => f (g x) The type of compose is inferred as: ('a -> 'b) * ('c -> 'a) -> ('c -> 'b) sml maths
That is a precise, abstract statement about function composition, independent of concrete numbers. This is reminiscent of category theory or function composition in set theory. When you write SML, the compiler proves that your implementation matches that abstract contract. SML has no for loops. Instead, you write recursive functions. This directly mirrors mathematical induction. datatype 'a tree = Leaf | Node of
When people think of programming languages for math, Python (with NumPy) or MATLAB usually come to mind. But there’s a quieter, older language that offers a uniquely elegant mathematical experience: Standard ML (SML) . This is reminiscent of category theory or function