Am Dienstag, den 04.02.2014, 10:41 +0900 schrieb Francois Berenger: > Hello, > > In a .ml file I'd like to write something like this > in order to factorize some code: > > let f x y z = [...] some code [...] > > module Something = struct > let g = f > end > > module Something_else = struct > let h = f > end > > Is calling Something.g or Something_else.h as efficient > as calling f directly? This is the same: For the calls of g and h ocamlopt generates code that actually calls f. Even the eta-expanded version is cheap: module Something = struct let g2 x y z = f x y z end The code for g2 consists just of a jump to the body of f. (And normally the inlining feature of ocamlopt even changes calls to g into calls to f.) Generally, ocamlopt is very good at function calls, no matter which variant (direct or indirect call, with or without curried arguments, inside an inner module or a functor). Don't put too much effort into optimizing this by hand. Gerd > > -- > Best regards, > Francois Berenger. > -- ------------------------------------------------------------ Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de My OCaml site: http://www.camlcity.org Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de ------------------------------------------------------------