2011-01-22 75 views
5

我是新来OCaml的,我不知道为什么,这是给我一个语法错误:OCaml的语法错误

type ('nonterminal, 'terminal) pe = 
| Empty 
| T of t 
| N of n 
| Seq of list 
| Choose of list 
| Star of e 
| Not of e;; 

type ('nonterminal, 'terminal) pe_tree = 
| Is_empty 
| Leaf of t 
| Node of (n,tree) 
| Sequence of list 
| Repeat of list 
| Is_not of e;; 

所有它的说法是,有一个语法错误就行14个字符0 -1(这是| Sequence of list是),我不明白为什么!

回答

8
type ('nonterminal, 'terminal) pe_tree = 
    | Is_empty 
    | Leaf of t 
    | Node of (n * tree) 
    | Sequence of list 
    | Repeat of list 
    | Is_not of e;; 

您使用*定义产品类型,如'a * 'b。虽然现在可能不太重要,但您应该知道Node of 'a * 'bNode of ('a * 'b)是不同的。您可以将它们分别视为具有两个参数的变体类型,而另一个变体类型具有一个参数(一个元组)。

还有一些其他的东西,

  • 你需要定义什么SequenceRepeat是列表。
  • 'nonterminal'terminal未使用;除非它们是幻像类型,我对此表示怀疑,它们可能应该用于签名的一部分。
+0

谢谢!我很困惑,因为我之前有另一个类型声明(我刚刚添加到我的原始问题),它的编译很好:/ – robocop 2011-01-23 00:40:43