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



Dmitry A. Kazakov wrote:

The question Georg asked was: where typed containers of elements of related
types might themselves appear related. The number of cases is huge.
Generics fundamentally cannot help here, they aren't dynamically
polymorphic.

But then wouldn't you again be mixing apples and herrings?

type APPLE_CONTAINER is new CONTAINER with null record;
-- specializes in apples, only

type HERRING_CONTAINER is new CONTAINER with null record;
-- specializes in herrings, only

x: access CONTAINER'class := ...;

x.insert(an_apple); -- right or wrong? compile time?


It is dynamic typing. The constraint check would happen at run-time. Too
late. You just have tossed a stinking herring in a jug apple cider...


3. Merging

You'll need to define a relational operator over your element type, but
then you can say:

Merge (C1.First, C2.First);


Same as above. I don't mix herrings and apples,

In fact, herrings with little pieces of apple aren't
that unusual, add onions and mayonnaise and you are
almost set - not everyone's taste, maybe. :-) Seriously,
wouldn't type-forcing containers be in the way of
composition?

How do you make a vector of doughnuts with different
toppings? Something like

zip(doughnuts.first, toppings.first);

seems reasonable to me.
.



Relevant Pages

  • Re: What doe sthis line mean?
    ... This is a generic class. ... define a generic container that can manipulate Apples or Potatoes, ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: EJB 3.0 vs Spring
    ... What are the major pros and cons of each approach? ... Apples and Oranges... ... You may want to ask which is better a JEE Container or a Spring ...
    (comp.lang.java.programmer)