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
Resources on OCaml's sharing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-03-10 (09:45)
From: Matthias Puech <puech@c...>
Subject: Resources on OCaml's sharing
Dear Camlists,

Does anyone know of a description of the sharing mechanism inside
Ocaml's heap (I guess)? I'm interested in any kind material, from a
formal account in a paper (even not directly related to Caml), to an
informal description and tips of usage, anything that could fill in my
shameful ignorance on that matter. Particularly, I'm trying to understand:
- where architecturally it takes place in the compiler,
- how it is an approximation from the perfect case of maximal sharing
(hash-consing I guess), i.e. what's the algorithm
- when can I safely state that a = b implies a == b.
- how is it that the function below is "smarter" than List.map? What do
we gain, what do we loose?

I understand sharing is part of ML's folklore and I didn't find any
resource on it, but maybe I missed something...

Thank you all in advance,


let rec list_smartmap f l = match l with
    [] -> l
  | h::tl ->
      let h' = f h and tl' = list_smartmap f tl in
	if h'==h && tl'==tl then l
	else h'::tl'