From: James Hague <jhague@dadgum.com>
To: caml-list@inria.fr
Subject: Numeric programming efficiency question
Date: Mon, 22 Mar 1999 12:33:11 -0600 (EST) [thread overview]
Message-ID: <Pine.LNX.3.96.990322122948.12166A-100000@babba.advancenet.net> (raw)
First of all, let me say that I've been having a great time learning
Objective CAML!
I implemented some simple functions that operate on three dimensional
vectors. After reading the "Numeric Programming in CAML" document, it
seems that, unfortunately, the code resulting from using a more classic
syntax is less efficient than using structures. That is, this:
let vadd (x0,y0,z0) (x1,y1,z1) = (x0 +. x1, y0 +. y1, z0 +. z1);;
generates poorer code than:
type vector = {x: float; y: float; z: float};;
let vadd a b = {x = a.x +. b.x; y = a.y +. b.y; z = a.z +. b.z};;
When using this function, one implementation has a more concise calling
syntax:
vadd (1.0,2.0,3.0) (10.0,20.0,30.0);;
vadd {x=1.0;y=2.0;z=3.0} {x=10.0;y.0;z=30.0};;
A utility routine makes the second option a little nicer:
let vec (a,b,c) = {x=a; y=b; z=c};;
This lets one write:
vadd vec(1.0,2.0,3.0) vec(10.0,20.0,30.0);;
I'm curious if the "shape changing" vec routine is optimized away in such
an expression. I would expect it to be, but that's just the wishful
programmer in me.
James Hague
next reply other threads:[~1999-03-22 19:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-03-22 18:33 James Hague [this message]
1999-03-23 17:12 ` Xavier Leroy
1999-03-23 19:32 ` James Hague
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=Pine.LNX.3.96.990322122948.12166A-100000@babba.advancenet.net \
--to=jhague@dadgum.com \
--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