OCaml 不喜欢函数的返回类型.这个函数以及我所有具有操作的函数都给了我错误

  • 本文关键字:函数 操作 错误 返回类型 不喜欢 OCaml ocaml
  • 更新时间 :
  • 英文 :


这个函数应该递归地告诉两个列表的每个元素的差异。但是当我运行它时,ocaml 不喜欢类型和串联。

let rec diffImRow image1Row image2Row =
    if List.length image1Row = 0
    then []
    else ((List.hd image2Row) - (List.hd image1Row)) :: diffImRow (List.hd image1Row), (List.hd image2Row)
;;

这段代码有几个问题: diffImRow (List.hd image1Row), (List.hd image2Row) 首先,您将每个列表的头部发送到 :: 运算符的右侧。您希望使用右侧每个列表的尾部进行递归。 此外,参数之间有一个逗号。代码的工作原理如下:

let rec diffImRow image1Row image2Row =
  if List.length image1Row = 0
  then []
  else ((List.hd image2Row) - (List.hd image1Row)) :: diffImRow (List.tl image1Row) (List.tl image2Row)

最新更新