Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] syntax bug: copying records
From: Mackenzie Straight <eizneckam@gmail.com>
> On 12/20/05, skaller <skaller@users.sourceforge.net> wrote:
> > If x is a record then { x } should be a copy of it. But this
> > doesn't work, I am using this ugly workaround instead:
> >
> > { x with dummy_field = x.dummy_field }
> >
> > Surely there is a better way?
> 
> Perhaps:
> 
> let copy (x:'a) = (Obj.obj (Obj.dup (Obj.repr x)) : 'a)

Not a very good idea:

  # copy 3;;
  Segmentation fault

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.

Jacques Garrigue