From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Ada.Locales pseudo-string types
Date: Thu, 09 Aug 2012 18:25:23 +0300
Date: 2012-08-09T18:25:23+03:00 [thread overview]
Message-ID: <a8i333Fc2uU1@mid.individual.net> (raw)
In-Reply-To: <ml7bnqhg2ndn$.urq4ojikfiv8$.dlg@40tude.net>
On 12-08-09 15:17 , Dmitry A. Kazakov wrote:
Niklas:
>>>> What I have sometimes found annoying is that operations on arrays of a
>>>> parent type cannot easily be applied to arrays of a derived type.
>>>> For example:
>>>>
>>>> type Parent is (A, B, C);
>>>> type Parent_Arr is array (Positive range <>) of Parent;
>>>>
>>>> procedure Print (Item : in Parent_Arr)
>>>> ...
>>>> end Print;
>>>>
>>>> type Child is new Parent;
>>>> type Child_Arr is array (Positive range <>) of Child;
Dmitry:
>>> If arrays had classes you could inherit the Parent's interface which would
>>> bring Print with it.
Niklas:
>> It is not clear to me how that would work, in detail. Either one would
>> have to override all the operations for Child_Arr, to substitude Parent
>> with Child, or there would have to be some implicit rules for such
>> substitutions, which would in effect establish the same implicit
>> relationship between Child_Arr and Parent_Arr as I feel already exists.
Dmitry:
> Yes. Either operations are implemented anew or else they are generated per
> composition of a conversion provided by the programmer with the operation
> of Parent.
So in the Child/Parent example, how would you "generate" the Print
operation for Child_Arr? How much more text would that need than the
current work-around, which is:
procedure Print (Item : in Child_Arr)
is
Parents : Parent_Arr(Item'Range);
begin
for P in Parents'Range loop
Parents(P) := Parent (Item(P));
end loop;
Print (Parents);
end Print;
(This work-around becomes longer for operations with "in out" parameters.)
Niklas:
>>>> The operation Print on Parent_Arr is not inherited by Child_Arr,
Dmitry:
>>> Why should it? Child_Arr is unrelated to Parent.
Niklas:
>> It is just a feeling, and sometimes a practical need. Surely Child_Arr
>> is in some sense related to Parent_Arr, since Child is related to
>> Parent, and the same type construction (array) is used in both?
Dmitry:
> type A is range 1..100;
> type B is range 1..100;
>
> How do you feel them, same, different?
Types A and B are different, but both are related to (derived from)
their (unnamed) 'Base types, and probably A'Base is the same as B'Base,
in which case both A and B inherit all operations of that type.
I don't think this example is similar to the Child/Parent example.
Niklas:
>> If a Child is-a Parent, in the sense that primitive operations for
>> Parents are also available (inherited) for Children, why are not
>> operations on collections of Parents available for collections of
>> Children? A collection (array) of Children is-a collection of Parents.
Dmitry:
> This relationship must be stated explicitly, e.g. Child implements the
> interface of Parent = Child and Parent are in the same class with the
> operations so and so defined.
"Must" is your opinion. I can disagree.
Dmitry:
>>> Somewhere in its
>>> declaration Child_Arr must say "new Parent" or "and Parent." Such type
>>> relationships must be manifested, not implied.
Niklas:
>> I'm not sure that making the relation manifest in that way is important.
Dmitry:
> How otherwise you could tell if Child could be used with Print?
(I assume you mean whether Child_Arr could be used with Print.) The
answer is: by making it a general language rule that "array of
derived-type" inherits operations from "array of parent-type" when the
index types match.
Dmitry:
> Child must
> be in the class of types having Print. Manifested typing requires this
> declared. It is a contract model.
Contracts (even in real law, I believe) can be implied, and can contain
implied requirements defined by general rules or laws. Whether they
should be manifest (explicitly written out) is a trade-off.
In this case, one should consider the possible harm, such as
ambiguities, coding errors, unreadability, etc. that the implicit
inheritance of (in this example) Print from Parent_Arr to Child_Arr
could cause, weigh it against the benefits, and then decide, based on
one's goals for the language. You consider the harm to be larger than
the benefit; I'm not sure yet.
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
next prev parent reply other threads:[~2012-08-15 2:48 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-06 16:45 Ada.Locales pseudo-string types Marius Amado-Alves
2012-08-06 17:10 ` Marius Amado-Alves
2012-08-06 19:15 ` J-P. Rosen
2012-08-06 19:34 ` Simon Wright
2012-08-06 20:07 ` Marius Amado-Alves
2012-08-06 20:57 ` Simon Wright
2012-08-06 21:09 ` Vasiliy Molostov
2012-08-06 23:07 ` Adam Beneschan
2012-08-06 23:23 ` Vasiliy Molostov
2012-08-06 23:46 ` Adam Beneschan
2012-08-07 1:17 ` Vasiliy Molostov
2012-08-07 7:20 ` Dmitry A. Kazakov
2012-08-07 7:43 ` Jacob Sparre Andersen
2012-08-09 20:47 ` Randy Brukardt
2012-08-07 8:44 ` Marius Amado-Alves
2012-08-07 13:14 ` Marius Amado-Alves
2012-08-07 15:42 ` Adam Beneschan
2012-08-07 18:22 ` Marius Amado-Alves
2012-08-07 20:10 ` Adam Beneschan
2012-08-07 20:42 ` Marius Amado-Alves
2012-08-07 21:38 ` Adam Beneschan
2012-08-08 7:04 ` Niklas Holsti
2012-08-08 7:18 ` Dmitry A. Kazakov
2012-08-08 7:37 ` Niklas Holsti
2012-08-08 8:09 ` Dmitry A. Kazakov
2012-08-08 11:14 ` Niklas Holsti
2012-08-08 11:59 ` Dmitry A. Kazakov
2012-08-08 14:01 ` Niklas Holsti
2012-08-09 7:48 ` Dmitry A. Kazakov
2012-08-09 8:31 ` Niklas Holsti
2012-08-09 12:17 ` Dmitry A. Kazakov
2012-08-09 15:25 ` Niklas Holsti [this message]
2012-08-09 16:43 ` Dmitry A. Kazakov
2012-08-08 8:28 ` J-P. Rosen
2012-08-08 11:35 ` Niklas Holsti
2012-08-08 14:05 ` Georg Bauhaus
2012-08-08 7:32 ` J-P. Rosen
2012-08-08 8:17 ` Niklas Holsti
2012-08-08 8:33 ` J-P. Rosen
2012-08-08 11:44 ` Niklas Holsti
2012-08-09 21:00 ` Randy Brukardt
2012-08-08 8:35 ` Dmitry A. Kazakov
2012-08-08 9:32 ` Marius Amado-Alves
2012-08-08 10:11 ` Dmitry A. Kazakov
2012-08-08 11:28 ` Marius Amado-Alves
2012-08-08 11:30 ` Marius Amado-Alves
2012-08-08 11:35 ` Marius Amado-Alves
2012-08-08 12:24 ` Dmitry A. Kazakov
2012-08-08 11:52 ` Niklas Holsti
2012-08-08 13:21 ` Dmitry A. Kazakov
2012-08-08 9:07 ` Marius Amado-Alves
2012-08-07 20:43 ` Marius Amado-Alves
2012-08-07 21:59 ` Robert A Duff
2012-08-07 22:19 ` Adam Beneschan
2012-08-08 0:37 ` Robert A Duff
2012-08-07 15:26 ` Adam Beneschan
2012-08-07 18:07 ` Marius Amado-Alves
2012-08-07 17:51 ` Simon Wright
2012-08-06 20:00 ` Marius Amado-Alves
2012-08-06 19:49 ` Jacob Sparre Andersen
2012-08-06 20:11 ` Marius Amado-Alves
2012-08-06 17:37 ` Michael Rohan
2012-08-06 18:23 ` Marius Amado-Alves
2012-08-06 19:36 ` Michael Rohan
2012-08-09 21:15 ` Randy Brukardt
2012-08-07 5:57 ` Jeffrey R. Carter
2012-08-07 15:46 ` Adam Beneschan
2012-08-07 17:51 ` Jeffrey R. Carter
2012-08-09 21:17 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox