From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: Francois Berenger <berenger@riken.jp>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] is there a runtime cost for this
Date: Tue, 04 Feb 2014 13:33:51 +0100 [thread overview]
Message-ID: <1391517231.19912.10.camel@e130> (raw)
In-Reply-To: <52F0455E.5040806@riken.jp>
[-- Attachment #1: Type: text/plain, Size: 1437 bytes --]
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
------------------------------------------------------------
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
next prev parent reply other threads:[~2014-02-04 12:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-04 1:41 Francois Berenger
2014-02-04 10:20 ` Goswin von Brederlow
2014-02-04 12:33 ` Gerd Stolpmann [this message]
2014-02-04 16:53 ` rixed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1391517231.19912.10.camel@e130 \
--to=info@gerd-stolpmann.de \
--cc=berenger@riken.jp \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox