我有以下代码:标准ML异常
- exception Negative of string;
> exn Negative = fn : string -> exn
- local fun fact 0 =1
| fact n = n* fact(n-1)
in
fun factorial n=
if n >= 0 then fact n
else
raise Negative "Insert a positive number!!!"
handle Negative msg => 0
end;
有什么不对的呢??我收到错误:
! Toplevel input:
! handle Negative msg => 0
! ^
! Type clash: expression of type
! int
! cannot have type
! exn
我该如何解决?如果用户输入一个负数,我希望函数通过例外返回0。
我也想知道如何显示一条消息,当用户输入一个负数,因为print()返回单位,但函数的其余部分返回int;