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
Re: Why OCaml sucks
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-05-10 (08:51)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Re: Why OCaml rocks
On Sat, May 10, 2008 at 10:24:50AM +0200, Berke Durak wrote:
> > (1) Ad-hoc polymorphic primitives (structural equality, marshalling
> > and hashing) do not work on ancient data structures, meaning that you
> > will need to provide your own comparison and hashing functions.  For
> > more details see Xavier Leroy's response here:
> As you cannot mutate anything that is ancient (since it might be
> concurrently
> accessed),

There are various restrictions on mutating the ancient data, which are
explained in the README.  It is not true that ancient data is
completely immutable, just that you really need to understand what
you're doing in order to do it correctly.  There are additional
restrictions to mutating [any] data concurrently, but I didn't explain
those because they are obvious, and can be solved with standard
threading techniques (mutexes, etc.)..

> you cannot mark or modify them in-place for ad-hoc marshalling or
> deep copying.  Is that correct?

I'm not sure what this means.  I haven't tried to Marshal ancient
data, because ancient data can already be persisted, so marshaling it
doesn't make much sense.

'Deep copying' of ancient data can be done just like deep copying any
other OCaml value.

> Comparison does not mark (and thus does not work on cyclic structures).
> Does it work on values in the ancient heap (I'm not talking of handles
> here)?

Your use of 'value', 'handle' etc. is confusing me.  I suggest you
take a look at how OCaml values are stored (eg. <caml/mlvalues.h> is a
good place to start).

Anyhow, the polymorphic primitives (like %compare) don't work, just
because they make the assumption that anything outside the normal
OCaml heap is incomparable, but you can certainly write your own
comparison functions to replace those, eg. comparing
character-by-character for strings.

This has nothing to do with 'marking'.

> So it seems that adding a generic copy-out-of-the-ancient heap function
> (which marks in a private area) would be worthwhile.  Should not be too
> difficult.

As I said earlier, you can just copy values from the ancient heap as
you would any other value, eg. using { ... with ... } syntax or
Array.copy / String.copy etc.

Let's say this again.  Values on the ancient heap look just like
values anywhere else in the program.  You can pass them to functions,
print them out, add them up, do whatever else you would normally do,
with very few restrictions.  The differences are:

  - the polymorphic primitives don't work (so you can't compare or hash them)
  - they don't get garbage collected
  - you should be very careful about mutating them


Richard Jones
Red Hat