2

ノードのリストとともに node というタイプを定義しました。

type node = {name: string; description: string}
nodes = [] : list(node)

createNewNode()新しいノードを作成し、selectedNode に割り当て、配列ノードに追加する関数を作成しました。

line 19: createNewNode() =
line 20:   selectedNode = {name="" remoteFSRoot=""} : node
line 21:   nodes = [nodes | selectedNode]
  ...

これをコンパイルすると、次のエラーが発生します。

Error
File "node.opa", line 21, characters 10-32, (21:10-21:32 | 592-614)
Expression has type { hd: list(node); tl: node } / 'c.a but is coerced into
list('a).
Types { name: string; description: string } and
{ hd: 'a; tl: list('a) } / { nil } are not compatible
Hint:
  One of the sum types may be missing the following cases of the
  other:
  { nil }
  { hd tl }.

このコンパイル メッセージの意味と修正方法を教えてください。

4

1 に答える 1

3

私はあなたが単純に逆nodesになりselectedNode、21行目で次のようになったと思います:

nodes = [selectedNode | nodes]
于 2011-09-09T16:25:48.733 に答える