【问题标题】:How can I declare a module (actually a Set.Make) in mli file?如何在 mli 文件中声明模块(实际上是 Set.Make)?
【发布时间】:2013-05-23 18:32:24
【问题描述】:

我有airport.mliairport.ml


airport.ml,我有

module AirportSet = Set.Make(struct type t = airport let compare = compare end);;

这没问题。


然后我有一个函数

val get_all_airport : unit -> AirportSet.t;;

,生成一个AirportSet


所以在airport.mli 中,我需要显示module AirportSet,以便识别AirportSet

我该怎么做?

【问题讨论】:

    标签: ocaml


    【解决方案1】:
    module AirportSet : (Set.S with type elt = airport)
    

    (括号实际上是不必要的,将它们放在那里以便您知道这是预期的签名,在一般情况下为sig ... end)。

    【讨论】:

      【解决方案2】:

      优雅的解决方案是gasche提出的;更实用/直接/天真的解决方案是简单地使用 ocaml-compiler ocamlc 为您推断 (-i) 模块的类型:

      ocamlc -i airport.ml
      

      这会给你一个更详细的类型,比如

      AirportSet :
        sig
          type elt = airport
          type t
          val empty : t
          val is_empty : t -> bool
          val mem : elt -> t -> bool
      ...
          val split : elt -> t -> t * bool * t
      end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多