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 JAA07722 for caml-red; Fri, 21 Jul 2000 09:23:47 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA19310 for ; Wed, 19 Jul 2000 21:21:36 +0200 (MET DST) Received: from csla.csl.sri.com (csla.csl.sri.com [192.12.33.2]) by concorde.inria.fr (8.10.0/8.10.0) with ESMTP id e6JJLZn23814 for ; Wed, 19 Jul 2000 21:21:35 +0200 (MET DST) Received: from cylinder.csl.sri.com (IDENT:filliatr@cylinder.csl.sri.com [130.107.15.112]) by csla.csl.sri.com (8.9.1/8.9.1) with ESMTP id MAA21221; Wed, 19 Jul 2000 12:21:28 -0700 (PDT) Received: (from filliatr@localhost) by cylinder.csl.sri.com (8.9.3/8.8.7) id MAA28624; Wed, 19 Jul 2000 12:21:28 -0700 X-Authentication-Warning: cylinder.csl.sri.com: filliatr set sender to filliatr@cylinder.csl.sri.com using -f From: Jean-Christophe Filliatre MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14709.65464.87345.229258@cylinder.csl.sri.com> Date: Wed, 19 Jul 2000 12:21:28 -0700 (PDT) To: David.Mentre@irisa.fr (David=?iso-8859-1?q?_Mentr=E9?=) Cc: caml-list@inria.fr Subject: Re: [newbie] Define and use records in sum types In-Reply-To: References: X-Mailer: VM 6.62 under Emacs 20.7.1 Reply-To: filliatr@csl.sri.com (Jean-Christophe Filliatre) Sender: weis@pauillac.inria.fr > 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 > I don't know what you want to do exactly, but I applied to following idea (which you can find in the ocaml sources) for AST tagged with common informations: type t = { name : string; info : u } and u = A | B of int (in the case of AST, t and u are really mutually recursive, with occurrences of t in the arguments of u's constructors) Then you can still make pattern-matching like this match x.info with A -> ... | B n -> ... and still access the name field with x.name. Hops this helps, -- Jean-Christophe Filliatre Computer Science Laboratory Phone (650) 859-5173 SRI International FAX (650) 859-2844 333 Ravenswood Ave. email filliatr@csl.sri.com Menlo Park, CA 94025, USA web http://www.csl.sri.com/~filliatr