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
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
谢谢你的帮助 !
解决方案
由于您向我们展示的代码摘录中的行数少于 65 行,因此错误消息显然不是您仅从该代码中得到的错误消息。请花时间创建一个mcve。
也就是说,紧跟最内层循环的then
分支是空的。您不能在 OCaml 中这样做:如果无事可做,则应通过返回(类型的唯一值)明确说明,如if
for
()
unit
if i != (n-1) && j != (n-1) then ()
else (* do the rest *)
推荐阅读
- deep-learning - 深度学习:如何处理输入大小的变化
- python - 无法通过 Python 连接到 Mysql 服务器(错误 111)
- javascript - 如何解决 Sequelize 更新问题?
- html - VScode Prettier 打破引用标签 - HTML5
- c++ - C ++如何将用户按键存储在变量中
- java - 使用 Runnable 进行多项活动的 UDP 接收器:android studio
- python - 如何在不计算 Python 中的时间数据列的情况下绘制时间序列
- javascript - Uncaught SyntaxError: missing ) 在来自 https://www.w3.org/TR/tcp-udp-sockets/ 的 TCP 示例中的参数列表之后
- flutter - Flutter 显示数组中的值
- python - 如何将日期范围传递给脚本?