comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: limited types (Was: Records that could be arrays)
Date: Tue, 28 Feb 2006 22:03:37 +0100
Date: 2006-02-28T22:03:37+01:00	[thread overview]
Message-ID: <zmqbsj55tlxb$.1wvaz50falap4$.dlg@40tude.net> (raw)
In-Reply-To: 1141156690.991228.267400@j33g2000cwa.googlegroups.com

On 28 Feb 2006 11:58:11 -0800, Matthew Heaney wrote:

> Dmitry A. Kazakov wrote:
>> On 28 Feb 2006 09:24:35 -0800, Matthew Heaney wrote:
>>
>> I still don't see CS.
> 
> I wrote the declaration wrong; it should have been:
> 
> generic
>   type ET is private;  --or: type ET (<>) is limited private;
>   type CT is private;  --cursor type
>   with function E (C : CT) return ET is <>;
> procedure Generic_Algorithm (C1, C2 : CT);
> 
> The cursor pair [C1, C2) describes a range of elements.  It might be
> the entire range of elements in the container, or just a subrange.  The
> algorithm doesn't care.

But still S <: T does not imply CS <: CT. 

>> BTW, if I had CS, would need not to instantiate Generic_Algorithm once
>> more.
> 
> (I assume "CS" means "container of element type S, and S derives from
> type T.")

Yes and CS should be a subtype of CT, so that CS could be passed as an "in"
where CT is expected. It also could be as an "out", but then with a chance
of Constraint_Error at run-time.

> As far as generic algorithms are concerned, it doesn't matter that type
> S derives from type T.  That's what "generic algorithm" means.

It means "works on a set of types." Generics are only one [weakest] form of
polymorphism.

> And yes, you have to instantiate the algorithm twice, since the cursor
> types come from different instantiations of some generic container
> package.

That is the whole point. BTW, you will need to instantiate it more than
twice for cross combinations, like when C1 is CS and C2 is CT. It
geometrically explodes.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2006-02-28 21:03 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-24 16:51 limited types (Was: Records that could be arrays) Thierry Bernier
2006-02-24 21:57 ` Randy Brukardt
2006-02-25  2:21   ` Matthew Heaney
2006-02-25  3:38     ` Matthew Heaney
2006-02-25 11:06   ` Dmitry A. Kazakov
2006-02-25 15:05     ` Matthew Heaney
2006-02-26  1:01       ` Randy Brukardt
2006-02-26  9:00       ` Dmitry A. Kazakov
2006-02-26 18:20         ` Matthew Heaney
2006-02-26 20:52           ` Dmitry A. Kazakov
2006-02-26 22:07             ` Matthew Heaney
2006-02-27  9:11               ` Dmitry A. Kazakov
2006-02-27 14:34                 ` Georg Bauhaus
2006-02-27 16:05                   ` Dmitry A. Kazakov
2006-02-27 16:52                     ` Matthew Heaney
2006-02-27 20:21                       ` Dmitry A. Kazakov
2006-02-27 21:40                         ` Georg Bauhaus
2006-02-28  9:38                           ` Dmitry A. Kazakov
2006-02-27 23:00                         ` Matthew Heaney
2006-02-28  9:39                           ` Dmitry A. Kazakov
2006-02-28 17:24                             ` Matthew Heaney
2006-02-28 19:06                               ` Dmitry A. Kazakov
2006-02-28 19:58                                 ` Matthew Heaney
2006-02-28 21:03                                   ` Dmitry A. Kazakov [this message]
2006-02-28 21:51                                   ` limited types Simon Wright
2006-03-01  1:59                                     ` 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