comp.lang.ada
 help / color / mirror / Atom feed
From: "Steven Deller" <deller@smsail.com>
To: <comp.lang.ada@ada.eu.org>
Subject: RE: Using "with function"
Date: Tue, 30 Oct 2001 17:45:23 -0500
Date: 2001-10-30T17:45:23-05:00	[thread overview]
Message-ID: <mailman.1004482124.1277.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <YKBD7.1073$Fm5.659253@news1.sttln1.wa.home.com>

> -----Original Message-----
> From: comp.lang.ada-admin@ada.eu.org
> [mailto:comp.lang.ada-admin@ada.eu.org]On Behalf Of Mark Lundquist
> Sent: Tuesday, October 30, 2001 12:50 PM
> To: comp.lang.ada@ada.eu.org
> Subject: Re: Using "with function"
...
> This is one of the things about Ada generics that might be a little
> counterintuitive until one gets the hang of it, don't you
> think?  A generic
> formal type is like a type declaration to the generic body,
> so words like
> "limited" and "abstract" have their normal meaning to the body (and
> technically, to the rest of the spec), which is that there are certain
> things you're not allowed to do there -- e.g. assigning to
> objects of a
> limited type, creating an object of an abstract type, etc.
> But for the
> instantiator, it's the flip side, and these words mean that
> the actual type
> is not required to have the corresponding properties.

Actually, it means *in all cases* that the actual type MUST have the
corresponding type properties, and it MAY have additional properties.

A non-abstract type has all the properties of an abstract type and then
some.  The reverse is not true, so an abstract type may *not* be an actual
for a non-abstract formal.

A non-limited type has all the properties of a limited type and then some.
The reverse is not true, so a limited type may *not* be an actual for a
non-limited formal.

A non-tagged type does *not* have all the properties of a tagged type.  The
reverse it true, so a tagged type may be used as the actual for a non-tagged
formal.

A formal states what properties of a type the generic code may use and
therefore, must be supplied in an instantiation.  It makes sense to use the
minimal set of type properties (and so state in the formal declaration), so
the widest set of types may be used to instantiate the generic.

> So the user of a
> generic should read "limited" as "allowed to be limited" (but can be
> limited); and while "tagged" indeed means "must be tagged",
> "abstract" means
> "is allowed to be abstract" (but can be non-abstract).

... "limited" as "must include properties of a limited type"
... "tagged" as "must include properties of a tagged type"
... "abstract" as "must include properties of an abstract type"

> The same goes for unknown discriminants in the generic formal type.
>
> For maximum flexibility, the rules of thumb for formal
> private types are:
>
> 1) Declare as limited, if possible.
> 2) Declare with unknown discriminants, if possible
> 3) For tagged formals, declare as abstract if possible

The rule of thumb is use a formal with the least amount of properties
possible.  Use "private" if possible.  Use "limited" if possible.  Leave out
"tagged" if possible.  Leave out discriminants if possible.  Use "abstract"
if possible.

With discriminants there is one quirk -- to allow an indefinite
discriminated type to be used in an instantiation, the formal must have a
discriminant part.  That is necessary so within the generic, use of the type
is able to "see" what the current discriminant is (to work with the type).
This is really just a corollary to the principle that an actual must have
the properties of the formal -- an indefinite discriminated type does not
have all the "properties" of a non-discriminated type.

Regards,
Steve
"Then, after a second or so, nothing continued to happen."
Steven Deller        Smooth Sailing LLC
410 757 6924         deller@smsail.com




  reply	other threads:[~2001-10-30 22:45 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-20 15:56 Using "with function" Matt Raikes
2001-07-21  5:21 ` tmoran
2001-07-21 20:30 ` Mark Lundquist
2001-10-29 17:58 ` Matthew Heaney
2001-10-30 17:49   ` Mark Lundquist
2001-10-30 22:45     ` Steven Deller [this message]
2001-11-03  4:15       ` Mark Lundquist
2001-11-03  5:11         ` Computer Language Shootout Eric Merritt
2001-11-03  6:50           ` tmoran
2001-11-03  7:15             ` Al Christians
2001-11-03  8:52           ` martin.m.dowie
2001-11-03 14:04             ` Ted Dennison
2001-11-03 14:24               ` martin.m.dowie
2001-11-03 14:49               ` Larry Kilgallen
2001-11-03 23:03                 ` research@ijs.co.nz
2001-11-04  6:39                   ` tmoran
2001-11-04 13:44                     ` Larry Kilgallen
2001-11-05  0:59                       ` Adrian Hoe
2001-11-05  8:04                       ` David Brown
2001-11-06  6:36                     ` AG
2001-11-06  8:05                       ` tmoran
2001-11-07  8:58                         ` AG
2001-11-06 12:07                       ` Larry Kilgallen
2001-11-07  6:19                       ` Richard Riehle
2001-11-04 15:59             ` Preben Randhol
2001-11-04 20:04               ` martin.m.dowie
2001-10-31  7:00   ` Using "with function" Richard Riehle
2001-10-31 15:58     ` Matthew Heaney
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox