OCaml 前向声明

发布于 2024-09-05 12:31:31 字数 622 浏览 6 评论 0原文

有没有办法在 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 并不是一种广泛使用的编程语言。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屋檐 2024-09-12 12:31:31

用于

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

具有递归类型。

Use

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

to have recursive types.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文