如何使用ocaml中的Y组合器调用具有多个参数的函数?

如何使用ocaml中的Y组合器调用具有多个参数的函数?,ocaml,y-combinator,ackermann,Ocaml,Y Combinator,Ackermann,我试图理解OCaml中的Y组合符。我从中获取了一些代码,并试图用它来编写Ackermann函数。在链接中的示例中,函数只需要一个参数。Ackermann函数需要两个参数,因此我一直有语法错误。到目前为止,我掌握的代码是 type 'a mu = Roll of ('a mu -> 'a);; let unroll (Roll x) = x;; let fix f = (fun x a -> f (unroll x x) a) (Roll (fun x a -> f (unr

我试图理解OCaml中的Y组合符。我从中获取了一些代码,并试图用它来编写Ackermann函数。在链接中的示例中,函数只需要一个参数。Ackermann函数需要两个参数,因此我一直有语法错误。到目前为止,我掌握的代码是

type 'a mu = Roll of ('a mu -> 'a);;

let unroll (Roll x) = x;;

let fix f = (fun x a -> f (unroll x x) a) (Roll (fun x a -> f (unroll x x) a));;

let acker f = function
  0, n -> n + 1
| m, 0 -> f (m-1) 1
| m, n -> f (m-1) (f m (n-1))
;;

print_int (fix (acker 2 2));;

我需要做什么才能让它工作?谢谢。

您正在将curried与uncarried函数定义混合在一起

以下是始终未结婚的阿克:

let acker f = function
  0, n -> n + 1
| m, 0 -> f (m - 1, 1)
| m, n -> f (m - 1, f (m, n - 1));;
这是一个电话:

# fix acker (2, 2);;
- : int = 7
#