0

I have code:

let join a ~with':b ~by:key = 
  let rec a' = link a ~to':b' ~by:key
      and b' = link b ~to':a' ~by:(Key.opposite key) in
  a'

and compilation result for it is:

Error: This kind of expression is not allowed as right-hand side of `let rec' build complete

I can rewrite it to:

let join a ~with':b ~by:key = 
  let rec a'() = link a ~to':(b'()) ~by:key
      and b'() = link b ~to':(a'()) ~by:(Key.opposite key) in
  a'()

It is compilable variant, but implemented function is infinitely recursive and it is not what I need.

My questions: Why is first implementation invalid? How to call two functions and use their results as arguments for each other?

My compiler version = 4.01.0

4

1 回答 1

1

第一个问题的答案在 OCaml 手册的第 7.3 节中给出。它是这样说的:

非正式地,接受定义的类由那些定义的名称仅出现在函数体内或作为数据构造函数的参数的定义组成。

您的名字显示为函数参数,这是不受支持的。

我怀疑原因是您不能以其他方式分配语义。在我看来,您看到的无限计算通常是无法避免的。

于 2014-10-24T20:30:55.947 回答