2011-09-09 19 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