views:

81

answers:

1

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..

+11  A: 

Use

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

to have recursive types.

Brian
Thanks, I usually don't have problems in discovering language features but OCaml is really different from what I've studied so far and I've only been able to find "phat" references of hundreds of pages that makes me lose orientation :)
Jack
Note that you can roll the dice and search for F# syntax/docs to learn OCaml. The core syntax is the same, and so e.g. http://stackoverflow.com/questions/1378575/f-forward-type-declarations is a win here.
Brian
that's a good point. I had to choose OCaml because they forced me. I thought it was an old although powerful language but if modern functional languages (Scala, F#) kept same syntax then this will turn out to be a nice choice :)
Jack
OCaml manual is a good read anyway: http://caml.inria.fr/pub/docs/manual-ocaml/manual016.html
ygrek