From: Niklas Holsti <nobody@nowhere.fi>
Subject: Re: Re-exporting primitive operations of a private type (like "-", and 'min)
Date: Mon, 31 Oct 2005 10:27:51 +0200
Date: 2005-10-31T10:27:51+02:00 [thread overview]
Message-ID: <ZDk9f.7943$M16.3294@reader1.news.jippii.net> (raw)
In-Reply-To: <slrndmbdiv.4s0.bogus_addy@tango.mindfuq.org>
Anonymous Coward wrote:
>>The whole point of private types is that the only visible operations
>>on them are assignment, equality and inequality, and any explicitly
>>defined operations in the visible part of the package
>>specification.
>
>
> That makes sense. As a default, it probably would be a poor language
> design to have private types automatically export public primitive
> operations. If I created an Altitude_Type, I wouldn't want to inherit
> the "+" operation.
The following is perhaps not quite on the original topic, but this
thread reminds me of an idea for a new feature related to private
types that I would like to present.
My Ada packages often define types that are *mostly* private in
the sense that I only want the clients to use a restricted set of
operations and properties of the type. However, I often do not
make these types actual private types because I want to reveal
some properties, such as discreteness, that I cannot now specify
for a private type.
I would like to be able to reveal some properties of private types
in the same way as we can now define generic formal types, for
example saying that the type is discrete (type T is (<>)) or is a
modular type (type T is mod <>). So I would like to write, for
example, a package like this:
package P is
type Element is private (<>);
-- This is not Ada. The intended meaning is that type
-- Element is private, but is a discrete type.
-- Some operations using Element.
private
type Element is (This, That, The_Other);
-- See, Element is really a discrete type.
end P;
Other (client) packages can then use the fact that P.Element is a
discrete type, for example by using P.Element as an index type:
with P;
package Client is
type Set is array (P.Element) of Boolean;
...
end Client;
However, the whole definition of P.Element would still be hidden,
so clients could not refer for example to P.Element'(P.This).
There would be a pleasing symmetry in this new feature if the
properties that could be revealed about a private type would match
exactly the properties that can now be defined for a generic
formal type. A private type with some properties revealed in this
way could then be used as the actual type to instantiate a generic
with a formal type that has matching properties.
There are even some places in the Ada LRM where the proposed
feature would be useful. For example, the LRM (95) now defines, in
13.7.1:
package System.Storage_Elements is
...
type Storage_Offset is range "implementation defined";
...
type Storage_Element is mod "implementation defined";
...
end System.Storage_Elements;
With the new feature, the "implementation defined" pseudocode
could be replaced by real code:
type Storage_Offset is private range <>; -- Not Ada.
type Storage_Element is private mod <>; -- Not Ada.
The full type declarations would be in the private part of the
package, as usual.
In such declarations, the "private" keyword is perhaps
unnecessary, since the presence of the box "<>" shows that the
declared type is partly hidden.
Does this idea appeal to anyone?
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
next prev parent reply other threads:[~2005-10-31 8:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-29 21:19 Re-exporting primitive operations of a private type (like "-", and 'min) Anonymous Coward
2005-10-30 8:57 ` Dmitry A. Kazakov
2005-10-30 9:18 ` Jeffrey R. Carter
2005-10-30 14:16 ` Martin Krischik
2005-10-30 22:35 ` Robert A Duff
2005-10-31 4:15 ` Anonymous Coward
2005-10-31 4:34 ` Anonymous Coward
2005-10-31 6:14 ` Jeffrey R. Carter
2005-11-01 3:39 ` Anonymous Coward
2005-11-01 4:47 ` Jeffrey R. Carter
2005-11-01 23:43 ` Anonymous Coward
2005-11-02 3:35 ` Jeffrey R. Carter
2005-11-01 14:11 ` Robert A Duff
2005-10-31 8:27 ` Niklas Holsti [this message]
2005-10-31 9:18 ` Dmitry A. Kazakov
2005-11-02 9:50 ` Jean-Pierre Rosen
2005-11-03 9:15 ` Niklas Holsti
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox