OCaml前向声明 [英] OCaml forward declaration

查看:97
本文介绍了OCaml前向声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在OCaml中进行C样式的前向声明?

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

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

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

推荐答案

使用

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

具有递归类型.

这篇关于OCaml前向声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆