English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2005-02-08 (17:07)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] [Benchmark] NBody
On Tue, 2005-02-08 at 23:04, Marcin 'Qrczak' Kowalczyk wrote:
> skaller <skaller@users.sourceforge.net> writes:
> > But the types in your record are mutable, and so it can't
> > possibly work.
> It does work: mutable floats are unboxed too (if there are no
> non-float fields).

I'm talking about fully unboxing an array of records of floats
into just an array of floats, and clearly that cannot be
done if the record contains a mutable field, because if you 
assign the record to two different array elements, then
modify the mutable field, both array elements would
have to reflect the assignment.

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

There certainly is for unboxed data structures: if you store
a record with an immutable field into a mutable field,
the immutable field becomes mutable, because you can
always use functional update. The mutability is thus
mutable if the parent is mutable, whether or not 
the field is mutable. In other words mutability is inherited.

In C++ this applies to lvalueness, but constness actually
works in reverse: a non-const field is const if its parent is.

For boxed fields, you may be right there is no propagation
in Ocaml, but perhaps that indicates a lack of expressiveness,
for example record subtyping is missing. In particular
one can believe that a function accepting a record
of immutable fields would not harm a record with the 
same structure but some mutable fields -- roughly
the equivalent of C++ 'const' conversions. However
unless I'm mistaken there is no way to do this,
even though it appears sound and desirable.
So saying 'there is nothing to propagate' isn't
really meaningful, it seems circular: Ocaml doesn't
propagate it therefore there isn't anything to

Note I didn't claim there was a bug, I said merely that

> it isn't clear Ocaml type system uses the most
> > expressive typing of 'constness',

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