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

时间:2015-03-13 02:42:51

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

1 个答案:

答案 0 :(得分:0)

这部分代码存在一些问题: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)
相关问题