我是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;;
Run Code Online (Sandbox Code Playgroud)
所有它说的是第14行字符0-1(这是哪里| Sequence of 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;;
Run Code Online (Sandbox Code Playgroud)
您可以使用它*来定义产品类型,如'a * 'b.虽然现在可能不太重要,但你应该知道Node of 'a * 'b并且Node of ('a * 'b)不同.您可以将它们视为具有两个参数的变体类型,另一个分别是具有一个参数(元组)的变体类型.
还有一些其他的东西,
Sequence,Repeat并列出.'nonterminal并且'terminal没有使用; 除非它们是幻影类型,我怀疑它们,它们可能应该用于签名的一部分.