2
我已經定義了一個稱爲節點的類型以及節點列表。將用戶定義的類型添加到數組中
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 }.
是什麼編譯消息意味着,如何解決?
是的,它始終是一些簡單的:)。謝謝您的幫助! – rancidfishbreath
如果你想確定,你也可以這樣做:List.add(elt,mylist)或List.cons(elt,mylist) – Fred