From: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
To: caml-list@inria.fr
Subject: Re: [Caml-list] [Benchmark] NBody
Date: Tue, 08 Feb 2005 13:04:37 +0100 [thread overview]
Message-ID: <87zmyfjm0a.fsf@qrnik.zagroda> (raw)
In-Reply-To: <1107855477.2555.95.camel@pelican.wigram> (skaller@users.sourceforge.net's message of "08 Feb 2005 20:37:58 +1100")
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).
It would be different if OCaml used standalone references instead
of mutable fields. But mutable fields are not first-class entities,
so they can be unboxed. I think this is actually the reason of
their existence (instead of taking SML ref as a primitive, which
is implemented with a record with a mutable field in OCaml).
> 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,
It does not optimize it, even though it theoretically could.
It's not clear whether this would be an optimization. Having a large
field unboxed requires boxing a large object if it's taken out of the
array as a whole - this is an improvement only if memory savings (and
thus cache usage and GC time) outweigh slower element access.
And it is generally taken out as a whole, unless a particular
operation could be applied to the copy inside the array directly.
This requires analysis which I believe OCaml doesn't perform.
Floats are small enough to be kept in registers.
> 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.
Since with the generic polymorphic representation of the array the
only way to implement it (in the absence of whole-program analysis)
is functional update, and it behaves exactly as functional update,
it's not surprising that OCaml doesn't allow this and requires to
use functional update explicitly.
> 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.
--
__("< Marcin Kowalczyk
\__/ qrczak@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
next prev parent reply other threads:[~2005-02-08 12:04 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-07 18:57 Christophe TROESTLER
2005-02-07 19:16 ` [Caml-list] " Will M. Farr
2005-02-07 19:36 ` Christophe TROESTLER
2005-02-07 19:55 ` Will M. Farr
2005-02-08 10:34 ` Olivier Andrieu
2005-02-08 10:52 ` Micha
2005-02-07 20:16 ` Markus Mottl
2005-02-07 19:37 ` Martin Jambon
2005-02-07 19:46 ` Christophe TROESTLER
2005-02-07 20:22 ` Martin Jambon
2005-02-07 20:04 ` sejourne_kevin
2005-02-07 20:32 ` Robert Roessler
2005-02-07 22:57 ` Oliver Bandel
2005-02-08 1:29 ` skaller
2005-02-08 1:48 ` Will M. Farr
2005-02-08 9:01 ` Ville-Pertti Keinonen
2005-02-08 9:37 ` skaller
2005-02-08 10:10 ` Ville-Pertti Keinonen
2005-02-08 16:36 ` skaller
2005-02-08 12:04 ` Marcin 'Qrczak' Kowalczyk [this message]
2005-02-08 17:06 ` skaller
2005-02-08 10:25 ` Xavier Leroy
2005-02-08 18:34 ` skaller
2005-02-08 10:43 ` Xavier Leroy
2005-02-08 11:26 ` Ville-Pertti Keinonen
2005-02-08 15:59 ` Florian Hars
2005-02-13 16:40 ` Christoph Bauer
2005-02-13 18:13 ` Christophe TROESTLER
2005-02-24 22:18 ` NBody (one more question) Christophe TROESTLER
2005-02-25 17:06 ` [Caml-list] " John Carr
2005-02-25 17:17 ` Christophe TROESTLER
2005-02-26 16:08 ` John Carr
2005-02-25 17:24 ` Ken Rose
2005-02-25 17:42 ` Oliver Bandel
2005-02-25 17:57 ` Xavier Leroy
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=87zmyfjm0a.fsf@qrnik.zagroda \
--to=qrczak@knm.org.pl \
--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;
as well as URLs for NNTP newsgroup(s).