如果在Ocaml有很多情况,

时间:2018-12-19 16:36:23

标签: 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
                    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;;

我收到以下错误消息:

File "s2.ml", line 65, characters 9-13:
Error: Syntax error

感谢您的帮助!

1 个答案:

答案 0 :(得分:4)

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

也就是说,紧接最里面的then循环之后的if的{​​{1}}分支为空。您无法在OCaml中执行此操作:如果无事可做,则应通过返回for()类型的唯一值)来明确表示,如

unit