如何在OCaml中定义两个相互引用的类型?

时间:2012-03-28 01:10:20

标签: types recursion ocaml

以下代码将报告语法错误消息:

type 'a edge = 
  |Empty 
  |End of 'a * 'a vertex * 'a vertex and
type 'a vertex = 
  |Empty
  |Vertex of 'a * 'a edge list;;

如何定义两种相互引用的类型?

1 个答案:

答案 0 :(得分:6)

第二个type在语法上不正确:

type 'a edge = 
  |Empty 
  |End of 'a * 'a vertex * 'a vertex
and 'a vertex = 
  |Empty
  |Vertex of 'a * 'a edge list;;