How do I define two types that refer to each other in OCaml?

The code below reports a syntax error message:

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

      

How do you define two types that refer to each other?

+3


source to share


1 answer


The second is type

not syntactically correct:



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

      

+6


source







All Articles