Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: Non-destructive record update??
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1998-04-20 (14:13)
From: Jacques GARRIGUE <garrigue@k...>
Subject: Re: Non-destructive record update??
From: Pierre Weis <>
Subject: Re: Non-destructive record update??
Date: Thu, 16 Apr 1998 16:19:18 +0200 (MET DST)

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

As long as we are going to discuss syntax, I would suggest:

	expr.{label1 = e1; label2 = e2; ...}

This is just a problem of parsing. With this definition you don't need
to change the production rules, just to add a

	expr ::= expr "." record

case to the dot notation. I believe it is also compact and
intuitive. And everybody knows how "." associates to the left.
Right, I'm overloading "." with another (related) meaning, but "with"
is also used elsewhere in the language, and we cannot add keywords

By the way the with notation would need non-trivial changes in the
parser, since the natural rule produces an ambiguous grammar:

	{ x = y; ... }

"x = y" may be parsed either as a field definition or as an
expression. If we parse it as an expression, then we are waiting for a
"with" clause, and end up with troubles. All right, no such expression
may return a record value, so in fact we might modify the definition:

	{ simple expr with label1 = e1; ... }

But usually Caml's grammar do not put restriction on expressions
between brackets...

	Jacques, a syntactic MLer
Jacques Garrigue      Kyoto University     garrigue at
		<A HREF=>JG</A>