![](/img/trans.png)
[英]Common Parse error: “in” in a function that call other functions OCaml
[英]Where to define common functions in Ocaml?
我有一些非常基本和簡單的函數由幾個.ml
文件共享:例如,warn,error ...我想知道,不是在每個.ml
文件中重復它們的定義,如何在一個公共位置定義它們,並在必要時打電話給他們? 它必然是一個模塊嗎?
非常感謝你!
OCaml中的每個文件都定義了一個模塊。 例如,您可以將常用定義放在:
(* common.ml *)
let error msg = ...
let warn msg = ...
然后從其他文件中使用它:
... Common.error "Naughty event!" ...
或者這樣:
open Common
... error "Naughty event!" ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.