我定义了一种称为节点的类型以及节点列表。
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 }.
此编译消息是什么意思以及如何修复它?
最佳答案
我认为您只是在第 21 行颠倒了 nodes
和 selectedNode
:
nodes = [selectedNode | nodes]
关于opa - 将用户定义的类型添加到数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7364517/