comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Enumeration literal visibility and use type
Date: 1998/05/26
Date: 1998-05-26T00:00:00+00:00	[thread overview]
Message-ID: <m3btsk8xoa.fsf@mheaney.ni.net> (raw)
In-Reply-To: 6kej65$dnh$1@hermes.seas.smu.edu


bralick@seas.smu.edu (William Bralick) writes:

> For some reason that I have yet to fathom, I had convinced myself 
> that "use type" would give immediate visibility of the enumerals in 
> doodah.cool_type.  I am now convinced that it doesn't (though I am
> ready to argue that it _should_).
> 
> Because sharing this information with my other team members will require
> that I eat more than a little crow ;-), I am looking for a pointer to 
> any information (chapter and verse in the rationale, an AI, anything ...) 
> that would explain _why_ Ada95 does not provide immediate visibility to 
> enumeration types that have been the object of a "use type" clause.

No, use type will NOT give you direct visibility to the enumeration literals.

I helps to understand the type model wrt to enumeration types.  In Ada,
an enumeration literal is modeled as a "primitive operation" of the
type.  Given this declaration,

type T is (E1, E2, E3);

it's as if it were declared like this:

type T;
function E1 return T;
function E2 return T;
function E3 return T;

The reason for this is that it allows different enumeration types in the
same scope to have the same values for literals, ie

type T2 is (E2, E3, E4);

O1 : T1 := E2;
O2 : T2 := E2;

The model is that E2 is a parameterless function returning a value of
the type.  Since each type is different, each "function" is different,
and so there is no confusion about what E2 means.  The usual name
resolution rules apply.

The issue is that "use type" only gives you direct visibility to the
predefined "operators" of a type; it does not give you direct visibility
to the predefined "operations" of a type.  Enumeration literals are
operations, not operators, and so aren't made directly visible by "use
type."

Does that explain it?

Matt

P.S.  Here's another example to illustrate how enumeration types work.
Given this declaration, 

generic
   type T is private; 
   function F return T;
package GP is ...;

I can instantiate it using an enumeration literal, passing it as the
generic actual "function":

package P is new GP (T, E2);

Pretty cool, eh?






  reply	other threads:[~1998-05-26  0:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-05-26  0:00 Enumeration literal visibility and use type William Bralick
1998-05-26  0:00 ` Matthew Heaney [this message]
1998-05-27  0:00   ` William Bralick
1998-05-27  0:00   ` Mats Weber
1998-05-27  0:00   ` John McCabe
1998-05-26  0:00 ` Roger Racine
1998-05-26  0:00 ` John McCabe
1998-05-26  0:00   ` David C. Hoos, Sr.
1998-05-26  0:00     ` Matthew Heaney
1998-05-27  0:00       ` John McCabe
1998-05-26  0:00     ` John English
1998-05-26  0:00     ` Ray Blaak
1998-05-27  0:00       ` John McCabe
1998-05-27  0:00         ` John McCabe
1998-05-27  0:00     ` Robert Dewar
1998-05-27  0:00       ` Matthew Heaney
     [not found] <6kej65$dnh$1@hermes.seas.smu.edu| <6kejt5$75u@gcsin3.geccs.gecm.com>
1998-05-26  0:00 ` William Bralick
1998-05-26  0:00   ` Fergus Henderson
1998-05-27  0:00     ` William Bralick
1998-05-27  0:00     ` John McCabe
1998-05-27  0:00       ` Peter Amey
1998-05-27  0:00         ` John McCabe
1998-05-27  0:00       ` Robert Dewar
1998-05-28  0:00         ` John McCabe
1998-05-28  0:00           ` Robert Dewar
1998-05-29  0:00             ` John McCabe
1998-05-28  0:00           ` Thomas Hood
1998-05-28  0:00             ` Robert Dewar
replies disabled

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