This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

Numeric programming efficiency question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 1999-03-22 (19:00) From: James Hague Subject: Numeric programming efficiency question
```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:

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: