The problem is the semicolon (;
) in the middle. Semicolons are allowed (optionally) at the end of a complete declaration, but right before and
is not the end of a declaration!
So the compiler is blowing up on the invalid declaration fun odd (n) = if n=0 then false else even (n-1)
that refers to undeclared even
. If it were to proceed, it would next blow up on the illegal occurrence of and
at the start of a declaration.
Note that there are only two situations where a semicolon is meaningful:
- the notation
(...A... ; ...B... ; ...C...)
means "evaluate ...A...
, ...B...
, and ...C...
, and return the result of ...C...
.
- likewise the notation
let ... in ...A... ; ...B... ; ...C... end
, where the parentheses are optional because the in ... end
does an adequate job bracketing their contents.
- if you're using the interactive REPL (read-evaluate-print loop), a semicolon at the end of a top-level declaration means "OK, now actually go ahead and elaborate/evaluate/etc. everything so far".
Idiomatic Standard ML doesn't really use semicolons outside of the above situations; but it's OK to do so, as long as you don't start thinking in terms of procedural languages and expecting the semicolons to "terminate statements", or anything like that. There's obviously a relationship between the use of ;
in Standard ML and the use of ;
in languages such as C and its syntactic descendants, but it's not a direct one.