Redundancy in OCaml type declaration (ml/mli)

前端 未结 5 413
北海茫月
北海茫月 2020-12-25 10:41

I\'m trying to understand a specific thing about ocaml modules and their compilation:

am I forced to redeclare types already declared in a .mli inside t

5条回答
  •  礼貌的吻别
    2020-12-25 11:45

    In general, yes, you are required to duplicate the types.

    You can work around this, however, with Camlp4 and the pa_macro syntax extension (findlib package: camlp4.macro). It defines, among other things, and INCLUDE construct. You can use it to factor the common type definitions out into a separate file and include that file in both the .ml and .mli files. I haven't seen this done in a deployed OCaml project, however, so I don't know that it would qualify as recommended practice, but it is possible.

    The literate programming solution, however, is cleaner IMO.

提交回复
热议问题