如果在Ocaml中有许多条件

如果在Ocaml中有许多条件,ocaml,Ocaml,我是oCaml的初学者,在以下函数上有一个错误: let rec determinant n m1 = if n <= 2 then detMat2 m1 else let mat = Array.make_matrix (n-1) (n-1) 0 in for ligne = 0 to (n-1) do for colonne = 0 to (n-1) do

我是oCaml的初学者,在以下函数上有一个错误:

let rec determinant n m1 = 
    if n <= 2 then 
        detMat2 m1
    else 
        let mat = Array.make_matrix (n-1) (n-1) 0 in 
            for ligne = 0 to (n-1) do
                for colonne = 0 to (n-1) do
                    for i = 0 to (n-1) do
                        for j = 0 to (n-1) do
                            if i != (n-1) && j != (n-1) then 
                                else if (i != ligne && j != colonne) then
                                    mat.(i).(j) <- m1.(ligne).(colonne)
                                else if i != ligne && j = colonne then 
                                    mat.(i).(j) <- m1.(ligne).(colonne+1)
                                else if i = ligne && j != colonne then
                                    mat.(i).(j) <- m1.(ligne+1).(colonne)
                                else if i = ligne && j = colonne then 
                                    mat.(i).(j) <- m1.(ligne+1).(colonne+1)                     
                        done                
                    done    
                done
            done;
    determinant (n-1) mat;;

谢谢你的帮助

由于您向我们展示的代码摘录中的行数远少于65行,因此错误消息显然不是仅从这段代码中得到的。请花点时间创建一个

也就是说,紧跟在最内层for循环后面的if的then分支是空的。在OCaml中不能这样做:如果没有什么要做的,则应该通过返回单元类型的唯一值来显式地表示,如中所示

if i != (n-1) && j != (n-1) then ()
else (* do the rest *)

请编辑你的帖子。您的错误消息与我们看到的实际代码不一致,没有第65行,这不是一个简单的示例。
if i != (n-1) && j != (n-1) then ()
else (* do the rest *)