Re: Generic procedures and their parameters



Maciej Sobczak <no.spam@xxxxxxxxxxx> writes:

But then, you would need to have even such fundamental things like
Integer belong to Ordered'Class. It's a shaky ground.

Why is that shaky? Integer IS ordered.

Regarding Array_Type being implied, it is not. You can have any number of
array types based on exactly same combination of index and element types.
These types will be different types:
type I is ...;
type E is ...;
type Array1 is array (I range <>) of E;
type Array2 is array (I range <>) of E;

The types Array1 and Array2 are distinct types.

And now I see. I'm still having troubles with the fact that
"granularity" of type system in Ada can be much smaller than what can be
achieved with structural differences only.

It's a good thing that Ada allows Array1 and Array2 above to be
different types. But sometimes, structural typing would be better. In
fact, Ada has moved a bit in that direction -- anonymous access types
use structural typing, more or less.

The next step would be getting "<" from the element type,
which would eliminate a need to have Sort generic.

No, I disagree. There is a place for generic subprograms, otherwise we'd
have everything in a single hierarchy with Object at the top. It's not a
coincidence that "other languages" drift towards supporting generics,
even if they already had such single-rooted hierarchies.

A hierarchy with Object at the top would be a Good Thing, IMHO. Trees
are more aesthetically pleasing than forests. But you're right that you
still need some sort of generic facility, so you can have strongly typed
containers. But I think perhaps we should have generic types
(i.e. parameterized types) rather than generic packages. That's what
discriminants do, but they're severely limited. It would make sense to
have a discriminant that is a type, so you could say:

My_Sequence: Sequence(Element => Integer) := (1, 2, 3);

- Bob
.



Relevant Pages

  • Wasted Efforts (Parametric polymorphism?)
    ... And even if below solves problems that are solved in generics or templates, does that necessarily mean that we can't come up with a better solution.. ... astrarray = array of string; ... procedure add(const item: AnyType var arr: AnyTypeArray); ...
    (borland.public.delphi.non-technical)
  • Re: Announcing CodeGear RAD Studio 2007
    ... genuine quest to determine where generics can be useful outside of the ... oft quoted example of type safe containers. ... if generics may be useful. ... How about an array copier? ...
    (borland.public.delphi.non-technical)
  • Re: A question related to type casting
    ... Given that the distinction already had to be worked around (you couldn't put an int in a List before Java 5), the added complexity would end up being rather pointless. ... Lack of support for value types means more than just the execution overhead of the boxing. ... For example, ArrayList<T> stores the elements in an array of type T. But, there's no way for the class to use an array of ints; it has to be Integer, with each array element a reference to a boxed int, and of course for there to be a separately allocated Integer instance for each non-null array element. ... You're correct that it would have been more complex to support generics in a reifiable way. ...
    (comp.lang.java.programmer)
  • Pointer to a generic type parameter
    ... I'm new in VC++ and have a question to generics. ... which contains an array of the generic type. ... I wanted to creat a class member which represents the pointer to the ...
    (microsoft.public.dotnet.languages.vc)
  • Re: generics and arrays and multi-class collections
    ... java.util.ArrayList uses an array of Object to store its ... The cast generates an unchecked warning. ... Wisdome is "use Java generics only at its shallowest". ...
    (comp.lang.java.programmer)

Loading