OCaml - 错误的功能类型

Pac*_*ane 1 oop ocaml types functional-programming

我已经制作了一个类方法,我想要这种类型:

unit -> (dir -> 'b)

但我的实际方法:

method iter () = fun x -> match x with
| Up -> if (Stack.is_empty pz) then raise Stack.Empty else if (Stack.length pz = 1) then failwith "Cannot go up" else (ignore (Stack.pop pz) ; {< a = (Stack.top pz) >})
| Down(v) -> match (Stack.top pz) with
| Noeud(o, {contents = []}) -> raise Not_found
| Noeud(o, {contents = l}) -> if mem_assoc v l then ((Stack.push (assoc v l) pz) ; {< a = (Stack.top pz) >} ) else raise Not_found
Run Code Online (Sandbox Code Playgroud)

有类型 unit -> dir -> 'b

我怎样才能成为第一种类型?

以下是自定义类型:

    type 'a arbre =  Noeud of 'a option ref * (char * 'a arbre) list ref
    type dir = Up | Down of char
Run Code Online (Sandbox Code Playgroud)

编辑:我需要这个,所以它可以符合某个接口,并且由于类型不匹配,它将无法编译.谢谢!

Ash*_*she 6

这不是问题.unit -> (dir -> 'b)unit -> dir -> 'bOCaml中的类型相同!(类型箭头是右关联的)

你能告诉我们实际的错误信息,以便我们知道问题所在吗?

附录:你真的试过这个吗?如果没有其他问题,那么你会发现它会只是工作.