types - OCaml 前向声明

标签 types ocaml forward-declaration

有没有办法在 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)
    ]

所以两种类型都必须知道另一种类型..我在 Google 上搜索了它,但不幸的是 OCaml 并不是一种广泛使用的编程语言..

最佳答案

使用

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

具有递归类型。

关于types - OCaml 前向声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3026123/

相关文章:

jQuery 插件不适用于 Angular 5(插件不是函数)

class - 如何使用 OCaml 中的类类型强制类中的 val 在类中不可变

ocaml - List.i 的未绑定(bind)值

forward-declaration - 前向声明和前向引用有什么区别?

c - 不理解我得到的这个前向声明(forward declaration)

java - Double 未存储正确的值

ocaml - 为什么 OCaml std lib 有这么多非尾递归函数?

ocaml menhir - 简单语法的流冲突结束

c++ - 方法返回类型的前向声明

c++ - 打印像二进制数一样存储的有符号整数