From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA05038 for caml-redistribution; Mon, 22 Mar 1999 20:00:12 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA01982 for ; Mon, 22 Mar 1999 19:34:03 +0100 (MET) Received: from babba.advancenet.net (babba.advancenet.net [205.198.248.21]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id TAA26616 for ; Mon, 22 Mar 1999 19:33:53 +0100 (MET) Received: from localhost (jhague@localhost) by babba.advancenet.net (8.9.3/8.9.3) with SMTP id MAA12570 for ; Mon, 22 Mar 1999 12:33:12 -0600 X-Authentication-Warning: babba.advancenet.net: jhague owned process doing -bs Date: Mon, 22 Mar 1999 12:33:11 -0600 (EST) From: James Hague X-Sender: jhague@babba.advancenet.net To: caml-list@inria.fr Subject: Numeric programming efficiency question Message-ID: x-no-archive: yes MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis 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