我遇到了类型 Num.num 的问题。我需要使用 Num 而不是 int,但程序出错。请帮我。谢谢。
# open Num;;
# let rec silnia n =
# if n < 2
# then 1
# else n * silnia(n-1)
#
# let rec newton n k =
# silnia n / (silnia k * silnia (n-k))
#
# let bell = [|1;1;2;5;15;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0|]
#
# let i = ref 2
# let k = ref 0
# let x = ref 0
# let z = ref 0
# let suma = ref 0
#
# let n = ref 5;;
val silnia : Num.num -> Num.num = <fun>
val newton : Num.num -> Num.num -> Num.num = <fun>
val bell : Num.num array = [|Num 1;Num 1;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0;Num 0|]
val i : Num.num ref = {contents = Num 2}val k : Num.num ref = {contents = Num 0}
val x : Num.num ref = {contents = Num 0}
val z : Num.num ref = {contents = Num }
val suma : Num.num ref = {contents = Num 0}
val n : Num.num ref = {contents = Num 4}
# if !n != 0 || !n != 1 then
# while !i <= !n do
# while !k <= (!i-1) do
# x := newton (!i-1) !k;
# suma := !suma + (!x * bell.(!k));
# k := !k + 1
# done;
# bell.(!k)<-(!suma);
# suma:=0;
# i:= !i + 1;
# done;;
File "", line 5, characters 29-31:
Error: This expression has type Num.num
but an expression was expected of type int
我不知道如何解决它。请更正或给我一些建议。谢谢。