Reputation: 5500
I have some very basic and simple functions shared by several .ml
files: for instance, warn, error... I would like to know, instead of repeating their definition in each .ml
file, how to define them in a common place, and just call them when necessary? Is it necessarily a module?
Thank you very much!
Upvotes: 3
Views: 244
Reputation: 24577
Every file in OCaml defines a module. For instance, you could place your common definitions in:
(* common.ml *)
let error msg = ...
let warn msg = ...
And then use it from other files as such:
... Common.error "Naughty event!" ...
Or as such:
open Common
... error "Naughty event!" ...
Upvotes: 5