From: Jean-Christophe Filliatre <filliatr@csl.sri.com>
To: David.Mentre@irisa.fr (David Mentré)
Cc: caml-list@inria.fr
Subject: Re: [newbie] Define and use records in sum types
Date: Wed, 19 Jul 2000 12:21:28 -0700 (PDT) [thread overview]
Message-ID: <14709.65464.87345.229258@cylinder.csl.sri.com> (raw)
In-Reply-To: <wd8d7kkewbr.fsf@parate.irisa.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:
>
> <ocaml>
> # type asp = A of { name : string } | B of { name : string ; ext : int };;
> -
> Syntax error
> </ocaml>
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
next prev parent reply other threads:[~2000-07-21 7:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-07-11 11:32 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 [this message]
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=14709.65464.87345.229258@cylinder.csl.sri.com \
--to=filliatr@csl.sri.com \
--cc=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