From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA11122 for caml-red; Sun, 16 Jul 2000 23:59:52 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA20630 for ; Tue, 11 Jul 2000 13:32:44 +0200 (MET DST) Received: from air.irisa.fr (air.irisa.fr [131.254.60.130]) by nez-perce.inria.fr (8.10.0/8.10.0) with ESMTP id e6BBWib23717 for ; Tue, 11 Jul 2000 13:32:44 +0200 (MET DST) Received: from parate.irisa.fr (parate.irisa.fr [131.254.12.25]) by air.irisa.fr (8.9.3/8.9.3) with ESMTP id NAA17280 for ; Tue, 11 Jul 2000 13:32:40 +0200 (MET DST) To: caml-list@inria.fr Subject: [newbie] Define and use records in sum types From: David.Mentre@irisa.fr (David=?iso-8859-1?q?_Mentr=E9?=) Date: 11 Jul 2000 13:32:40 +0200 Message-ID: User-Agent: Gnus/5.0805 (Gnus v5.8.5) Emacs/20.6 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: weis@pauillac.inria.fr 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: # type asp = A of { name : string } | B of { name : string ; ext : int };; - Syntax error However, I can use intermediate names: # 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 It *seems* to work but, in fact, the a_rec definition is masked by b_rec definition: # 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 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.