如何在SML的if条件的其他部分"无所作为"

JAN*_*JAN 3 sml smlnj

在SML中,我必须使用该else部分,因为这些是语言的规则.

else那时我怎么能做什么呢?

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;
Run Code Online (Sandbox Code Playgroud)

Pas*_*uoq 5

else ()
Run Code Online (Sandbox Code Playgroud)

价值()是该unit类型的独特居民.它使得整个if-then-else结构的类型很好,因为then分支也有类型unit.

最后,在某些ML变体if e1 then e2中可以用作快捷方式if e1 then e2 else (),但不能用于SML.