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 (11:01)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] syntax bug: copying records
On Wed, 2005-12-21 at 19:41 +0900, Jacques Garrigue wrote:
> 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?

> 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.

Why not?

If I write

	let x = expr in ...

then the type of x is determined by the type of expr unified
with the uses of x, right?

So the same inference doesn't apply to

	let x = { expr } in ..

instead, { .. } is required to have a definite type?
Couldn't this be checked instead, so that one could write:

	let x = { expr : thetype } in

which IMHO is preferable to picking one of the fields,
since the latter is fragile wrt the names of the fields.

How would you copy Lexing.lexbuf .. whose contents 
could be construed as implementation dependent?

Or worse .. a private record type .. which you *cannot*
copy with functional update .. although perhaps one could
argue if there is no copy constructor given it shouldn't
be copyable .. hmm.

John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net