Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Pierre Weis <weis@pauillac.inria.fr>
To: Christophe.Raffalli@univ-savoie.fr
Cc: Donald.Syme@cl.cam.ac.uk, caml-list@pauillac.inria.fr
Subject: Re: Non-destructive record update??
Date: Thu, 16 Apr 1998 16:19:18 +0200 (MET DST)	[thread overview]
Message-ID: <199804161419.QAA16455@pauillac.inria.fr> (raw)
In-Reply-To: <199804251226.OAA01300@lama-d132.univ-savoie.fr> from "Christophe Raffalli" at Apr 25, 98 02:26:43 pm

> The syntax could be
> 
> *   x.y <- 2 (may be confusing with mutable syntax ?)
> 
> *   let y = 2 in record x 
> 
> Or anything else, but there really should be something !

We propose the notation {expr with label1 = e1; lable2 = e2 ... } to
mean the record returned by the expression expr with fields label1,
label2, ... set to values e1, e2, ...

This is reminiscent of the usual (functionnal) notation for records,
and does not confuse with field update.

As an example, you may define functionnal translations for points as:

type point = {x : float; y : float; color : int};;

let translate q = {q with x = q.x +. 1.0};;

As an additional benefit, this notation provides a simple way to
define default values for records fields. For example:

let default_point = {x = 0.0; y = 0.0; color = black};;

let p = {default_point with x = 2.0};;

> With the second syntax it is easy to extend the parser, 
> and you could have a "and" to update more than one field, with only one copy
> of the original record:
> 
>     let y = 2 and z = 3 in record x
> 
>  This is not the case with the straight forward compilation of:
> 
>     (x.y <- 2).z <- 3

This new way of defining records is also straightforward to compile.

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/







  reply	other threads:[~1998-04-16 14:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-04-09 15:02 Caml sur Rhapsody Pierre Weis
1998-04-14 23:27 ` Non-destructive record update?? Donald Syme
1998-04-25 11:26   ` Christophe Raffalli
1998-04-16 14:19     ` Pierre Weis [this message]
1998-04-16 14:47       ` Pascal Brisset
1998-04-17  0:26       ` Jacques GARRIGUE

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199804161419.QAA16455@pauillac.inria.fr \
    --to=weis@pauillac.inria.fr \
    --cc=Christophe.Raffalli@univ-savoie.fr \
    --cc=Donald.Syme@cl.cam.ac.uk \
    --cc=caml-list@pauillac.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox