Ocaml 在corebuild下编译时出现奇怪的错误

Ocaml 在corebuild下编译时出现奇怪的错误,ocaml,Ocaml,我真的不明白发生了什么事。我有以下代码: let rec interleave n l = match l with [] -> [[n]] | head::tail -> (n::l)::(List.map (~f:fun y -> head::y) (interleave n tail)) in let rec aux l = match l with [] -> [l] | head::tail -> List.concat ( List.m

我真的不明白发生了什么事。我有以下代码:

let rec interleave n l = 
match l with
  [] -> [[n]]
  | head::tail -> (n::l)::(List.map (~f:fun y -> head::y) (interleave n tail))
in let rec aux l =
match l with
  [] -> [l]
  | head::tail -> List.concat ( List.map (interleave head) (aux tail) )
使用ocaml进行编译时,它会按照预期进行编译和工作,但在corebuild下,会出现以下错误:

表达式的类型为'a list->`列表列表,但表达式为 应为“b”类型列表


它是否又与标签有关(正如您从
~f:fun y->…
中看到的,它以前已经让我恼火了)?如果是,我应该使用什么类型的标签以及在哪里?

您需要重新阅读手册中有关标签参数的部分内容

let rec interleave n l = 
match l with
  | [] -> [[n]]
  | head::tail -> (n::l)::(List.map ~f:(fun y -> head::y) (interleave n tail))
and aux l =
match l with
  | [] -> [l]
  | head::tail -> List.concat ( List.map ~f:(interleave head) (aux tail) );;
注意:标记参数的正确语法是
~label:expression


注意:Core List.map函数的类型为
'a List->f:('a->'B)->'B List
,如果忘记在函数
f
中添加标签,它将尝试用函数统一第二个参数。这就是为什么会出现如此奇怪的错误消息。

我原以为函数
~f
只添加到“lambda”函数中,但现在它有了意义