类型声明中的OCaml语法错误
我是OCaml新手,不知道为什么会出现语法错误:类型声明中的OCaml语法错误,ocaml,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
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出现语法错误(这就是| list序列的位置),我不知道为什么
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
中所述。虽然现在可能不太重要,但您应该知道,'a*'b的节点和('a*'b)
的节点是不同的。您可以将它们视为具有两个参数的变量类型,而另一个分别是具有一个参数(元组)的变量类型
还有一些其他的事情
- 您需要定义什么是
Sequence
和Repeat
李>
'非终端
和'终端
不使用;除非它们用于幻影类型(我对此表示怀疑),否则它们可能应该用于签名的一部分
谢谢!但我还是很困惑,因为我前面还有另一个类型声明(我刚刚添加到我的原始问题中),而且它的编译很好:/必须有更多的类型定义t
,e
以及我提到的其他内容都没有定义。这两个定义都不应该像您显示的那样编译。哦,好的,我明白了。现在很明显,哈哈,我不知道为什么我会有这么多麻烦-谢谢!