Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to define two types referring to each other in OCaml?

The code below will report 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 to define two types referring to each other?

like image 322
lkahtz Avatar asked Oct 15 '25 05:10

lkahtz


1 Answers

The second type is not syntactically correct:

type 'a edge = 
  |Empty 
  |End of 'a * 'a vertex * 'a vertex
and 'a vertex = 
  |Empty
  |Vertex of 'a * 'a edge list;;
like image 156
Rafe Kettler Avatar answered Oct 19 '25 02:10

Rafe Kettler