ocaml中的二进制搜索树中的某些错误

问题描述 投票:0回答:1
type (ty1,ty2) btree = Empty
  | Node of (ty1,ty2) * (ty1,ty2) btree * (ty1,ty2) btree;;

这是我写一个构造函数的代码。为合适的类型(ty1,ty2) treety1写下类型ty2的OCaml表达式,它们表示我们感兴趣的树。

When I run that 
7 | type (ty1,ty2) btree = Empty
          ^^^
Error: Syntax error
tree ocaml comments computer-science
1个回答
0
投票

类型变量需要加撇号'作为前缀,以将它们与具体类型区分开。

Node的第一个参数的语法也无效。我认为您的意思是成为一个元组:

type ('ty1, 'ty2) btree = Empty
  | Node of ('ty1 * 'ty2) * ('ty1, 'ty2) btree * ('ty1, 'ty2) btree;;
© www.soinside.com 2019 - 2024. All rights reserved.