Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: limited typ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 18 of 26 Topic 4222 of 5930
Post > Topic >>

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

by "Dmitry A. Kazakov" <mailbox@[EMAIL PROTECTED] > Feb 28, 2006 at 10:38 AM

On Mon, 27 Feb 2006 22:40:18 +0100, Georg Bauhaus wrote:

> 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?

You cannot tell without the contract of Container. The above could be
compile error, run-time error or correct.

There are three [all useful] variants:

1. Containers of related types are unrelated
2. Containers of related types are same
3. Containers of subtypes are subtypes (polymorphic containers)

[there is also an axis for the container index/cursor types]

The variants 1 and 2 are relatively easy to get. The variant 3 is much
more
challenging.

Consider [imaginary syntax]:

type Food is ...
type Food_Container is ..; -- of Food'Class
type Apple is new Food with ...;
type Herring is new Food with ...;

type Apple_Box is new Food_Container (Element'Tag => Apple'Class);
type Herring_Barrel is new Food_Container (Element'Tag => Herring'Class);

X : Food_Container'Class := Some_Herring_Barrel;
Y : Herring_Barrel := Some_Herring_Barrel;

X.Insert (An_Apple); -- Constraint_Error at run-time
Y.Insert (An_Apple); -- Constraint_Error at run-time + compiler warning

With full ADT one could also do this

   type Apple_Only_Box is new Food_Container some syntax sugar;
private
   type Apple_Only_Box is array (...) of Apple;
      -- The implementation of the container is completely overridden
      -- and replaced by a more efficient

> In fact, herrings with little pieces of apple aren't
> that unusual, add onions and mayonnaise and you are
> almost set -

rather pickled red beets and cu***bers ...

> not everyone's taste, maybe. :-)

Not in a class of apple juice! (:-))

> Seriously,
> wouldn't type-forcing containers be in the way of
> composition?

It will, when that is what's needed. It should be programmer's choice. And
it is much more flexible that the choices we have now: either same type or
different types. Ada was always better than that. Consider Integer and
Positive as an example.

Now what about an array of Integers vs. an array of Positives. Then a
slice
of an array of Positives. Presently, constraints cannot propagate between
types. This is a weakness of the type system. You cannot get an array
subtype by constraining its elements. You cannot get an access subtype by
constraining the target type. This is more general and im****tant question
than just container types.

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




 26 Posts in Topic:
limited types (Was: Records that could be arrays)
Thierry Bernier <email  2006-02-24 16:51:03 
Re: limited types (Was: Records that could be arrays)
"Randy Brukardt"  2006-02-24 15:57:46 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-25 02:21:13 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-25 03:38:59 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-25 12:06:20 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-25 15:05:02 
Re: limited types (Was: Records that could be arrays)
"Randy Brukardt"  2006-02-25 19:01:06 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-26 10:00:07 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-26 18:20:39 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-26 21:52:32 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-26 22:07:00 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-27 10:11:28 
Re: limited types (Was: Records that could be arrays)
Georg Bauhaus <bauhaus  2006-02-27 15:34:58 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-27 17:05:47 
Re: limited types (Was: Records that could be arrays)
"Matthew Heaney"  2006-02-27 08:52:23 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-27 21:21:08 
Re: limited types (Was: Records that could be arrays)
Georg Bauhaus <bauhaus  2006-02-27 22:40:18 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-28 10:38:31 
Re: limited types (Was: Records that could be arrays)
"Matthew Heaney"  2006-02-27 15:00:29 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-28 10:39:20 
Re: limited types (Was: Records that could be arrays)
"Matthew Heaney"  2006-02-28 09:24:35 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-28 20:06:50 
Re: limited types (Was: Records that could be arrays)
"Matthew Heaney"  2006-02-28 11:58:11 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-28 22:03:37 
Re: limited types
Simon Wright <simon@[E  2006-02-28 21:51:52 
Re: limited types
Matthew Heaney <matthe  2006-03-01 01:59:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 22:16:36 CDT 2008.