From: Vu Ngoc San <san.vu-ngoc@ujf-grenoble.fr>
To: Caml Mailing List <caml-list@yquem.inria.fr>
Subject: function definition
Date: Sun, 21 Jan 2007 13:45:41 +0100 [thread overview]
Message-ID: <45B36075.5000608@ujf-grenoble.fr> (raw)
I'm sure this is a basic question:
what is the difference between these ways of defining a function, and
what is the most efficient (I mean for the resulting function f = binop
o f1 f2, which typically will be called x*1000 times)
type operator = Plus | Minus;;
let binop1 o f1 f2 =
fun x -> match o with
| Plus -> (f1 x) +. (f2 x)
| Minus -> (f1 x) -. (f2 x)
let binop2 o f1 f2 =
match o with
| Plus -> fun x -> (f1 x) +. (f2 x)
| Minus -> fun x -> (f1 x) -. (f2 x)
let binop3 o f1 f2 =
let op = match o with
| Plus -> (+.)
| Minus -> (-.) in
fun x -> op (f1 x) (f2 x)
let binop4 o f1 f2 =
fun x ->
let op = match o with
| Plus -> (+.)
| Minus -> (-.) in
op (f1 x) (f2 x)
Thanks for your expertise !
San
next reply other threads:[~2007-01-21 12:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-21 12:45 Vu Ngoc San [this message]
2007-01-21 17:42 ` [Caml-list] " Jon Harrop
2007-01-23 11:44 ` Vu Ngoc San
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=45B36075.5000608@ujf-grenoble.fr \
--to=san.vu-ngoc@ujf-grenoble.fr \
--cc=caml-list@yquem.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