Recursion 如何定义相互递归的类型

Recursion 如何定义相互递归的类型,recursion,ocaml,typing,reason,Recursion,Ocaml,Typing,Reason,我有以下代码: type cellInfo('a) = { index: int, column: column('a), id: string }; type cellInfoFn('a) = cellInfo('a) => ReasonReact.reactElement; type column('a) = { header: string, accessor: accessor('a), id: option(string), cell: cellI

我有以下代码:

type cellInfo('a) = {
  index: int,
  column: column('a),
  id: string
};

type cellInfoFn('a) = cellInfo('a) => ReasonReact.reactElement;

type column('a) = {
  header: string,
  accessor: accessor('a),
  id: option(string),
  cell: cellInfoFn('a),
};
看看每种类型是如何相互依赖的

我收到以下错误消息:

[1]   12 │ type cellInfo('a) = {
[1]   13 │   index: int,
[1]   14 │   column: column('a),
[1]   15 │   id: string
[1]   16 │ };
[1]
[1]   This type constructor's parameter, `column`, can't be found. Is it a typo?

如何处理相互递归的类型定义?

相互递归的定义必须用
分隔。这适用于
let
定义和
type
定义:

type cellInfo('a) = {
  index: int,
  column: column('a),
  id: string
}

and cellInfoFn('a) = cellInfo('a) => ReasonReact.reactElement

and column('a) = {
  header: string,
  accessor: accessor('a),
  id: option(string),
  cell: cellInfoFn('a),
};

看起来好像成功了。谢谢这是否可能/它在多个文件中看起来如何?不,它们必须在同一个文件中定义。处理跨文件的相互递归的一种常见做法是将它们放在同一个文件中,然后将它们别名回它们“所属”的位置。这也适用于模块吗?我想它们可以私下定义,以后放入模块中。只要模块在同一个文件中,它就可以工作。您还必须使用
rec
关键字,如
let
,并为每个模块提供签名。