7

有没有办法在 OCaml 中进行 C 风格的前向声明?

我的问题是我有两个相互引用的变体:

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)
    ]

所以这两种类型都必须知道另一种。我在谷歌上搜索过,但不幸的是 OCaml 不是一种如此广泛使用的编程语言。

4

1 回答 1

16

采用

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

有递归类型。

于 2010-06-11T20:56:46.027 回答