簡體   English   中英

如何在 utop 中加載.ml 文件及其對應的.mli 文件?

[英]How to load .ml file with its corresponding .mli file in utop?

簡單地說,假設我有一個名為moduleExample.ml的實現文件和一個位於同一目錄中的名為moduleExample.mli的接口文件。

我怎樣才能將它們一起加載,以使接口moduleExample.mli中未列出的功能從moduleExample.mlutop的簽名中隱藏? 此外,如何通過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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM