3

SML ではelse、言語のルールであるため、part を使用する必要があります。

その状態でどうすれば何もできません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;
4

1 に答える 1

5
else ()

()は、unit型の固有の居住者です。thenブランチにも type があるため、if-then-else 構造全体が適切に型付けされunitます。

最後に、一部の ML バリアントでif e1 then e2は のショートカットとして使用できますがif e1 then e2 else ()、SML では使用できません。

于 2013-01-06T09:19:07.973 に答える