GTD*_*Dev 2 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: cellInfoFn('a),
};
Run Code Online (Sandbox Code Playgroud)
看看每种类型如何相互依赖.
我收到以下错误消息:
[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?
Run Code Online (Sandbox Code Playgroud)
我如何处理相互递归的类型定义?
相互递归定义必须用and
.这适用于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),
};
Run Code Online (Sandbox Code Playgroud)