Re: language design implications for variant records in a pascal-like language

Robert A Duff <bobduff@shell01.TheWorld.com>
Fri, 24 Dec 2010 12:50:20 -0500

          From comp.compilers

Related articles
language design implications for variant records in a pascal-like lang noitalmost@cox.net (noitalmost) (2010-12-22)
Re: language design implications for variant records in a pascal-like gneuner2@comcast.net (George Neuner) (2010-12-23)
Re: language design implications for variant records in a pascal-like danielzazula@gmail.com (Daniel Zazula) (2010-12-24)
Re: language design implications for variant records in a pascal-like bobduff@shell01.TheWorld.com (Robert A Duff) (2010-12-24)
Re: language design implications for variant records in a pascal-like mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2010-12-25)
Re: language design implications for variant records in a pascal-like DrDiettrich1@aol.com (Hans-Peter Diettrich) (2010-12-25)
Re: language design implications for variant records in a pascal-like gene.ressler@gmail.com (Gene) (2010-12-27)
Re: language design implications for variant records in a pascal-like bobduff@shell01.TheWorld.com (Robert A Duff) (2010-12-27)
Re: language design implications for variant records in a pascal-like noitalmost@cox.net (noitalmost) (2010-12-27)
Re: language design implications for variant records in a pascal-like cr88192@hotmail.com (BGB) (2010-12-27)
[52 later articles]
| List of all articles for this month |
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Newsgroups: comp.compilers
Date: Fri, 24 Dec 2010 12:50:20 -0500
Organization: The World Public Access UNIX, Brookline, MA
References: 10-12-040
Keywords: design
Posted-Date: 25 Dec 2010 16:26:44 EST

noitalmost <noitalmost@cox.net> writes:


> My question is this: Would variant records provide significant value to a user
> of my language (given that classes were implemented)?


No.


Take a look at Ada as an example of a language that has both features.
It's for historical reasons: Ada 83 had variant records (pretty much
the same as Pascal), and object-oriented features were added in the
1995 version.


A variant record is basically an upside-down class hierarchy.


Ada's variant records can do some things that classes can't. Variant
records are not extensible, so the compiler knows all the variants,
and so does the programmer. If there are four variants, the tag field
can fit in 2 bits. You can't do that with classes (unless you're
willing to do whole-program analysis). And you can do case statements
on the tag field of a variant record, and the compiler can check that
you didn't forget any of the possibilities.


You could decide you don't care about these "features" of variant
records. Or you could design your class feature so that the
programmer can optionally specify all the possibilities up front.
Usually, you don't want to do that, because you want extensibility.
But there are exceptions. For example, in Smalltalk, Boolean is a
class with two subclasses True and False. But the extensibility there
is an illusion: if somebody added a third subclass of Boolean, it
would break most programs. Boolean is fundamentally two-valued; it's
not at all "object oriented".


You should also check out how types are declared in OCaml.


- Bob



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.