Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: David.Mentre@irisa.fr (David Mentré)
To: caml-list@inria.fr
Subject: [newbie] Define and use records in sum types
Date: 11 Jul 2000 13:32:40 +0200	[thread overview]
Message-ID: <wd8d7kkewbr.fsf@parate.irisa.fr> (raw)

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.



             reply	other threads:[~2000-07-16 21:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-07-11 11:32 David Mentré [this message]
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é

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=wd8d7kkewbr.fsf@parate.irisa.fr \
    --to=david.mentre@irisa.fr \
    --cc=caml-list@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