Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [newbie] Define and use records in sum types
@ 2000-07-11 11:32 David Mentré
  2000-07-17 10:01 ` Markus Mottl
  2000-07-19 19:21 ` Jean-Christophe Filliatre
  0 siblings, 2 replies; 13+ messages in thread
From: David Mentré @ 2000-07-11 11:32 UTC (permalink / raw)
  To: caml-list

Hello dear camlists,

I have problems with basic record and sum types use.

I would like to define a sum type with records as constructor
parameters, records with the same field names. 

I have tried the follwing definition:

<ocaml>
# type asp = A of { name : string } | B of { name : string ; ext : int };;
                  -
Syntax error
</ocaml>

However, I can use intermediate names:

<ocaml>
# type a_rec = { name : string };;
type a_rec = { name : string; } 
# type b_rec = { name : string ; ext : int };;
type b_rec = { name : string; ext : int; } 
# type asp = A of a_rec | B of b_rec ;;
type asp = A of a_rec | B of b_rec
</ocaml>

It *seems* to work but, in fact, the a_rec definition is masked by b_rec
definition:

<ocaml>
# let a_b = B({name = "n" ; ext=3 }) ;;
val a_b : asp = B {name="n"; ext=3}
# let an_a = A({name="n"});;
               ----------
Some record field labels are undefined
</ocaml>

So my question is: is it possible to define a sum of records with the
same field names? 


The rationale behind this question: I find records more clear that
tuples in source code.


Best regards,
david
-- 
 David.Mentre@irisa.fr -- http://www.irisa.fr/prive/dmentre/
 Opinions expressed here are only mine.



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

end of thread, other threads:[~2000-07-25 22:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-11 11:32 [newbie] Define and use records in sum types David Mentré
2000-07-17 10:01 ` Markus Mottl
     [not found]   ` <14709.63462.792269.194367@ish.artisan.com>
2000-07-19 20:10     ` Markus Mottl
2000-07-21 12:23       ` Frank Atanassow
2000-07-21 20:00         ` Markus Mottl
2000-07-22 13:34           ` Frank Atanassow
2000-07-22 18:31             ` Markus Mottl
2000-07-23 13:55               ` Frank Atanassow
2000-07-23 15:20                 ` Markus Mottl
2000-07-24  9:28                   ` Frank Atanassow
2000-07-25  5:26                     ` Alan Schmitt
2000-07-19 19:21 ` Jean-Christophe Filliatre
2000-07-20  7:08   ` David Mentré

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox