I am trying to write a function in SML that takes an integer and outputs the number of digits int he number. For example, user inputs 122, I want to output 3. I thought this functions would do the trick but I am getting some errors in regards to result constraints of clauses not agreeing. And right-hand-side doesn't agree and operator and operand don't agree. I am very new to ML and I do not know what I am doing wrong! Thanks in advance.
fun num_digits nil = nil
| num_digits 0 = 1
| num_digits n =
let
val x = 1
fun f(z, a) =
let
val c = z+1
val m = a div 10
in
if m >= 1
then
f(c, m)
else z
end;
in
f(x, n)
end;