Ocaml style: parameterize programs

I have an OCaml program that has a lot of functions that depend on a parameter, i.e. "dimensions". This parameter is determined once at the beginning of the code run and remains constant until completion.

My question is: how can I write code shorter, so my functions do not all require the dimension parameter. These modules call functions from each other, so there is no strict hierarchy between the modules (or I do not see this).

How does ocaml style address this issue? Should I use functors or are there other ways?

+4
source share
1 answer

, , , . , , "". " ":

let hidden_box = ref None
let initialize_param p =
  match !hidden_box with None -> hidden_box := Some p | _ -> assert false
let param =
  lazy (match !hidden_box with None -> assert false | Some p -> p)

, Lazy.force param .

ETA: , " ":

  • false,
  • - .

(2) . (3) .

+3

All Articles