0
我试图做一个功能,使得它输出列表中删除相邻的重复OCaml的预期类型“一
let rec rem_adj_duplicates l =
let rec utn l n = match l with
[] -> n
| (x :: y :: xs) -> if (x != y) then utn (y::xs) (n::x)
else utn (y::xs) n
in utn l []
我收到以下错误:
Error: This expression has type 'a list but an expression was expected of type 'a The type variable 'a occurs inside 'a list
为什么ñ希望键入'a而不是'列表?
我想要的是将x添加到列表n的末尾。 –
这是一个非常慢的操作,所以不是你真正想在生产代码中做的事情:-)但是这个表达式是'n @ [x]'。 –
好吧,那有效,但我实际上只限于不使用@运算符:/ –