Re: limited types (Was: Records that could be arrays)



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
.



Relevant Pages

  • Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl)
    ... All you need to do is write the generic in terms of container ... a generic on an array instead of a container. ... procedure Generic_Op (C: Cursor); ... instantiate the generic algorithm. ...
    (comp.lang.ada)
  • Re: Equivalent to VCLs DataModule
    ... System.ComponentModel.Container in a CLR object in order to have that object act as a container for other objects at design time? ... that the class derives either from Form or Component, though I don't know for sure. ...
    (microsoft.public.dotnet.framework)