In SML I must use the else part , since those are the rules of the language .
How can I do nothing in the else condition then ?
fun calc(input : string ) : int =
let
val outStr = ref "someString"
val outInt = ref 0
in
outInt := (validateHelper(input) handle _ => ~1);
if (outInt <> ~1)
then
( outStr := replaceRomanDec(input); (* replace roman number with decimal *)
outInt := (calcMyRomanExpression(!outStr) handle _ => ~1);
)
else (* nada *)
!outInt
end;
The value
()is the unique inhabitant of theunittype. It makes the whole if-then-else construct well-typed, since thethenbranch also has typeunit.Finally, in some ML variants
if e1 then e2can be used as shortcut forif e1 then e2 else (), but not in SML.