Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sml 在ML中处理异常_Sml_Smlnj - Fatal编程技术网

Sml 在ML中处理异常

Sml 在ML中处理异常,sml,smlnj,Sml,Smlnj,各位,我正试图了解异常在ML中是如何工作的,但我有一个奇怪的错误,我无法找出问题所在: exception Factorial fun checked_factorial n = if n < 0 then raise Factorial else n; fun factorial_driver () = checked_factorial(~4) handle Factorial => print "Out of range."; 异常

各位,我正试图了解异常在ML中是如何工作的,但我有一个奇怪的错误,我无法找出问题所在:

exception Factorial 

fun checked_factorial n =
  if n < 0 then
    raise Factorial 
  else n;

fun factorial_driver () =
    checked_factorial(~4)
  handle
    Factorial => print "Out of range.";
异常阶乘 复因子n= 如果n<0,则 提升阶乘 else n; 有趣的阶乘驱动程序()= 检查因子(~4) 手柄 阶乘=>打印“超出范围”;
可能出了什么问题?提前感谢您的帮助。

您需要确保
factorial\u驱动程序的类型一致。非异常情况返回
int
,因此ML推断函数类型为
unit->int
,但异常情况(即
print
表达式)返回
unit
,而不是
int

通常,在所有情况下,基本上都需要返回相同类型的值