Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OCaml forward declaration

Is there a way to do a C-style forward declaration in OCaml?

My problem is that I have two variants which mutually refer to each other:

type path_formula =
  [ `Next of state_formula
  | `Until of (state_formula * state_formula)
  | `UntilB of (state_formula * int * state_formula)  
  ]

type state_formula = 
    [ `True | `False
    | `Not of state_formula
    | `And of (state_formula * state_formula)
    | `Or of (state_formula * state_formula)
    | `Imply of (state_formula * state_formula)
    | `Label of string
    | `Prob` of (boundf * path_formula)
    | `Expc` of (boundi * formula)
    ]

So both type must know the other one.. I searched for it on Google but unfortunately OCaml is not a so wide-use programming language..

like image 336
Jack Avatar asked Jun 11 '10 20:06

Jack


1 Answers

Use

type T1 = ...
and T2 = ...

to have recursive types.

like image 66
Brian Avatar answered Oct 26 '22 13:10

Brian