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
syntax bug: copying records
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-12-21 (18:07)
From: Mackenzie Straight <eizneckam@g...>
Subject: Re: [Caml-list] syntax bug: copying records
On 12/21/05, Jacques Garrigue <garrigue@math.nagoya-u.ac.jp> wrote:
>   # copy 3;;
>   Segmentation fault

I know. You can check the tag first if you really want. Like this:

let copy x =
  let r = Obj.repr x in
  if Obj.is_block r then
    Obj.obj (Obj.dup r)

Of course, we all know that using Obj is equivalent to using a dirty
syringe you found on the sidewalk, so... Danger!

> This also explains why you need at least one record field in the
> "with" notation, otherwise there is no way to know for sure the type
> of the record you're copying.

True. Well, you don't actually need to know the type (indeed, the
runtime system needs to have enough information to copy values). But I
imagine it could have disastrous consequences when copying abstract
values anyway.