![](/img/trans.png)
[英]OCaml share structure between mli file and signature inside ml file
[英]How to load .ml file with its corresponding .mli file in utop?
簡單地說,假設我有一個名為moduleExample.ml
的實現文件和一個位於同一目錄中的名為moduleExample.mli
的接口文件。
我怎樣才能將它們一起加載,以使接口moduleExample.mli
中未列出的功能從moduleExample.ml
在utop
的簽名中隱藏? 此外,如何通過moduleExample.mli
文件進行類型抽象?
我認為這樣做的正確方法,或者更一般地在頂層加載多個模塊和接口的整個項目,是使用構建系統來編譯所有模塊並將它們鏈接到頂層。
使用 沙丘,您可以按照此處所述執行dune utop directory
。 為了詳盡無遺,這里有一個架構示例:
沙丘.ml
(library
(name dummy)
(wrapped false)
)
例程
type t = int
let of_int x = x
let to_string = string_of_int
let add = (+)
let print x = print_string (to_string x)
例子.mli
type t
val of_int : int -> t
val print : t -> unit
通過執行dune utop.
然后在模塊Ex
上使用#show
指令,給出:
utop # #show Ex;;
module Ex : sig type t val of_int : int -> t val print : t -> unit end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.