我已经定义了一个名为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 }.
这个编译消息意味着什么,我该如何修复它?
答案 0 :(得分:3)
我认为您只是在第21行反转了nodes
和selectedNode
:
nodes = [selectedNode | nodes]