From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Why no abstract non-tagged types?
Date: Mon, 24 Feb 2014 15:12:28 -0800 (PST)
Date: 2014-02-24T15:12:28-08:00 [thread overview]
Message-ID: <d7be9093-da8e-41e9-b86b-c138e4418325@googlegroups.com> (raw)
In-Reply-To: <90153ba2-ffe8-4696-8459-d81a0f703c9e@googlegroups.com>
On Thursday, February 20, 2014 8:04:08 PM UTC-7, Britt wrote:
> Recently I've been wishing I could declare some otherwise conventional enumeration types as "abstract" so they could only be used as a template for derived types.
>
> Such abstract types couldn't be used directly for object declarations. For example:
>
> type Valve_State_Base_Type is abstract (Unknown, Open, Closed); -- in Ada 202X
>
> Valve_State : Valve_State_Base_Type; -- illegal, type is abstract
You already have this ability in Ada... in fact you've had it since Ada 83:
Generic
Package Abstract_Enumeration is
Type Enumeration is (Value_1, Value_2, Value_3, Value_4, Value_5);
End Abstract_Enumeration;
If you WITH Abstract_Enumeration you cannot directly use Abstract_Enumeration.Enumeration, you need to instantiate it first:
Package Enums is new Abstract_Enumeration;
Package Other_Enums is new Abstract_Enumeration;
Defines two instances of Enumeration, one fore Enums and another for Other_Enums, although they have the same names they are incompatible w/o type-casting.
-----
[More recent Ada-specs]
If you wanted something like subtypes, you could have a generic something like:
Generic
with Package AE is new Abstract_Enumeration(<>);
First : AE.Enumeration := AE.Enumeration'First;
Last : AE.Enumeration := AE.Enumeration'Last;
Package Enumeration_Subtype is
Subtype Enumeration_Subtype is AE.Enumeration range First..Last;
End Enumeration_Subtype;
prev parent reply other threads:[~2014-02-24 23:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-21 3:04 Why no abstract non-tagged types? Britt
2014-02-21 8:33 ` Dmitry A. Kazakov
2014-02-26 18:52 ` Dan'l Miller
2014-02-26 20:55 ` Dmitry A. Kazakov
2014-02-26 21:40 ` Eryndlia Mavourneen
2014-02-24 23:12 ` Shark8 [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox