Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Benchmark] NBody
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] [Benchmark] NBody
On Tue, 2005-02-08 at 12:48, Will M. Farr wrote:
> Doesn't caml store records whose types are all floats as a float array 
> anyway?  I thought I remembered this optimization going by in the 
> manual somewhere.

But the types in your record are mutable, and so it can't
possibly work.

In particular, given two arrays of a record type R containing
a mutable field M, the arrays MUST uses boxes or modifications
to M in a shared record wouldn't be shared.

OTOH if the field is not mutable there is no problem,
but then you can't modify it, you can only use
functional update on the record and store the whole
thing back into the array.

Perhaps Ocaml is actually smart enough to optimise

	type r = { m: float; n: float };
	let x = Array.create 99 { m=0.0; n=0.0 } in
	x.[2] = { x.[2] with m = m + 1.0 };

so x is represnted by an array of float, and perhaps
one could even optimise

	x.[2].m <- 22.0;

even though it appears to be a type error (modifying
an immutable field), it actually isn't, since you could
always used functional update.

However it isn't clear Ocaml type system uses the most
expressive typing of 'constness', i.e. that it propages
'mutable' ness correctly. 

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net