2011-09-09 4 views
2

노드 목록과 함께 node라는 유형을 정의했습니다.배열에 사용자 정의 유형 추가

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

I는, 새로운 노드를 생성 selectedNode에 할당하고, 노드 어레이에 추가 createNewNode()라는 함수를 만들었다.

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 }. 

무엇이 컴파일 메시지가 의미합니까 내가 그것을 어떻게 수정합니까?

답변

3

나는 당신이 단순히 라인 (21)에 nodesselectedNode를 반전 생각 :

nodes = [selectedNode | nodes] 
+0

네, 그것은 항상 뭔가 간단한 :)입니다. 도와 주셔서 감사합니다! – rancidfishbreath

+0

확신하고 싶다면 다음과 같이 할 수도 있습니다 : List.add (elt, mylist) 또는 List.cons (elt, mylist) – Fred

관련 문제