Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] default values for record field definitions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] default values for record field definitions
Hi,

On Wed, Jul 18, 2001 at 09:13:47PM -0700, Alexander V. Voinov wrote:

> Why not to introduce a syntax for default values of record fields:
> type rec1 = { attr1: type1 = val1; attr2: type2; attr3: type3 = val3 }
> 
> It this case constructions of the form
> let x = { attr2 = val2 } are possible, with other fields filled by val1,
> val3.
> 
> Can it be done via camlp4?

No, it is not purely syntactic. The definition type has to generate a
"normal" type definition *plus* some appropriate function to set the
default values to the undefined fields. This is possible to do that
in Camlp4, but I don't see what interface give to this function.

And for the record usage, it should call this function, but I am not
sure it is possible. And we have to change that for all defined record
expressions. Simpler if there is a specific syntax for those records.
And I am not sure it would be enough.

An argument to say that it is not syntactic is the fact that the record
fields have a meaning, what is typically a work at typing time. The fact
that "attr2" is a record field (with a default value or not) is typing.
In Camlp4, at parse time, there is no link between the "attr2" of the
record definition and the "attr2" of the record expression. They can
even exist in different compilation units: in this case, syntactic analysis
can do nothing.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr