caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] default values for record field definitions
@ 2001-07-19  4:13 Alexander V. Voinov
  2001-07-19  6:43 ` Ian Zimmerman
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Alexander V. Voinov @ 2001-07-19  4:13 UTC (permalink / raw)
  To: caml

Hi All,

It may well be that I'm not in the first hundred of those who proposed
this, if so - sorry :-).

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?

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] default values for record field definitions
  2001-07-19  4:13 [Caml-list] default values for record field definitions Alexander V. Voinov
@ 2001-07-19  6:43 ` Ian Zimmerman
  2001-07-19 13:35   ` David Mentre
  2001-07-19  7:02 ` Dmitry Bely
  2001-07-21 13:16 ` Daniel de Rauglaudre
  2 siblings, 1 reply; 7+ messages in thread
From: Ian Zimmerman @ 2001-07-19  6:43 UTC (permalink / raw)
  To: OCAML


Alexander> Why not to introduce a syntax for default values of record
Alexander> fields:

Alexander> type rec1 = { attr1: type1 = val1; attr2: type2; attr3:
Alexander> type3 = val3 }

Alexander> It this case constructions of the form

Alexander> let x = { attr2 = val2 } are possible, with other fields
Alexander> filled by val1, val3.

type rec1 = { attr1: type1; attr2: type2; attr3: type3 };
let rec1_default = { attr1 = val1; attr2 = val2; attr3 = val3 } in
let x = { rec1_default with
        attr2 = val2'
         }
and ...

BTW, I couldn't find this in the manual!

-- 
Ian Zimmerman, Oakland, California, U.S.A.
EngSoc adopts market economy: cheap is wasteful, efficient is expensive.
GPG pub key: 433BA087 9C0F 194F 203A 63F7 B1B8 6E5A 8CA3 27DB 433B A087
-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] default values for record field definitions
  2001-07-19  4:13 [Caml-list] default values for record field definitions Alexander V. Voinov
  2001-07-19  6:43 ` Ian Zimmerman
@ 2001-07-19  7:02 ` Dmitry Bely
  2001-07-19 16:20   ` Alexander V. Voinov
  2001-07-20  9:42   ` FabienFleutot
  2001-07-21 13:16 ` Daniel de Rauglaudre
  2 siblings, 2 replies; 7+ messages in thread
From: Dmitry Bely @ 2001-07-19  7:02 UTC (permalink / raw)
  To: caml-list

"Alexander V. Voinov" <avv@quasar.ipa.nw.ru> writes:

> It may well be that I'm not in the first hundred of those who proposed
> this, if so - sorry :-).
> 
> 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?

Why don't you like

type rec1 = { attr1: type1; attr2: type2; attr3: type }
let default_rec1 = { attr1 = init_val1; attr2 = init_val2; attr = init_val3 }
...
let x = { default_rec1 with attr2 = val2 }

?

Hope to hear from you soon,
Dmitry


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] default values for record field definitions
  2001-07-19  6:43 ` Ian Zimmerman
@ 2001-07-19 13:35   ` David Mentre
  0 siblings, 0 replies; 7+ messages in thread
From: David Mentre @ 2001-07-19 13:35 UTC (permalink / raw)
  To: Ian Zimmerman; +Cc: OCAML

Ian Zimmerman <itz@speakeasy.org> writes:

> BTW, I couldn't find this in the manual!

It is burried in it: paragraph 7.5 at
http://caml.inria.fr/ocaml/htmlman/manual020.html


d.
-- 
 David.Mentre@inria.fr
 Opinions expressed here are only mine.
-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] default values for record field definitions
  2001-07-19  7:02 ` Dmitry Bely
@ 2001-07-19 16:20   ` Alexander V. Voinov
  2001-07-20  9:42   ` FabienFleutot
  1 sibling, 0 replies; 7+ messages in thread
From: Alexander V. Voinov @ 2001-07-19 16:20 UTC (permalink / raw)
  To: caml-list

Hi All,

Ian Zimmerman wrote:

> type rec1 = { attr1: type1; attr2: type2; attr3: type3 };
> let rec1_default = { attr1 = val1; attr2 = val2; attr3 = val3 } in
> let x = { rec1_default with
>         attr2 = val2'
>          }

Dmitry Bely wrote:

>
> type rec1 = { attr1: type1; attr2: type2; attr3: type }
> let default_rec1 = { attr1 = init_val1; attr2 = init_val2; attr = init_val3 }
> ...
> let x = { default_rec1 with attr2 = val2 }
>

Yes, this is nice. But it's a workaround.

Alexander

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] default values for record field definitions
  2001-07-19  7:02 ` Dmitry Bely
  2001-07-19 16:20   ` Alexander V. Voinov
@ 2001-07-20  9:42   ` FabienFleutot
  1 sibling, 0 replies; 7+ messages in thread
From: FabienFleutot @ 2001-07-20  9:42 UTC (permalink / raw)
  To: Caml List

> > Why not to introduce a syntax for default values of record fields:
> > type rec1 = { attr1: type1 = val1; attr2: type2; attr3: type3 = val3 }
>
> Why don't you like
> type rec1 = { attr1: type1; attr2: type2; attr3: type }
> let default_rec1 = { attr1 = init_val1; attr2 = init_val2; attr =
init_val3 }
> ...
> let x = { default_rec1 with attr2 = val2 }

That seems to be the most usual workaround, but it'd be nice to allow
writing:

let x = {default_rec1 with (* Nothing! *) }

to produce a copy of default_rec1 instead of a pointer to it, as would do:

let x = default_rec1

(useful when there are some mutable fields). It doesn't seem to be difficult
to add to the compiler...
-------------------
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] default values for record field definitions
  2001-07-19  4:13 [Caml-list] default values for record field definitions Alexander V. Voinov
  2001-07-19  6:43 ` Ian Zimmerman
  2001-07-19  7:02 ` Dmitry Bely
@ 2001-07-21 13:16 ` Daniel de Rauglaudre
  2 siblings, 0 replies; 7+ messages in thread
From: Daniel de Rauglaudre @ 2001-07-21 13:16 UTC (permalink / raw)
  To: caml

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2001-07-21 13:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-19  4:13 [Caml-list] default values for record field definitions Alexander V. Voinov
2001-07-19  6:43 ` Ian Zimmerman
2001-07-19 13:35   ` David Mentre
2001-07-19  7:02 ` Dmitry Bely
2001-07-19 16:20   ` Alexander V. Voinov
2001-07-20  9:42   ` FabienFleutot
2001-07-21 13:16 ` Daniel de Rauglaudre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).