OCaml forward declaration

偶尔善良 提交于 2019-12-23 09:30:05

问题


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


回答1:


Use

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

to have recursive types.



来源:https://stackoverflow.com/questions/3026123/ocaml-forward-declaration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!