comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Your wish list for Ada 202X
Date: Wed, 9 Apr 2014 12:40:26 +0200
Date: 2014-04-09T12:40:26+02:00	[thread overview]
Message-ID: <1w6eh0aiksmdh$.1h16p7y0b8c6h.dlg@40tude.net> (raw)
In-Reply-To: li217v$uvk$1@loke.gir.dk

On Tue, 8 Apr 2014 18:37:35 -0500, Randy Brukardt wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
> news:yl8s1sbhw0lw.1bhypcrvreord.dlg@40tude.net...
>> On Mon, 7 Apr 2014 20:15:10 -0500, Randy Brukardt wrote:
> ...
>>> Mixed operations are not the Ada way of typing.
>>
>> It is Ada's way of SUBtyping. Obviously Unbounded_String and String are
>> related subtypes, promoted to types due to implementation reasons only.
> 
> Obvious to you only. Any single program/subsystem should stick to a single 
> string type. The fact that you can't do that in Ada (unless that type is 
> String) is the bug that needs to be fixed.

I don't understand what you are trying to say. Is it that no program shall
use both Unbounded_String and String or that there must be no String
(Unbounded_String) at all?

>>>>> There is no opportunity to share implementations, which is the other
>>>>> reason to inherit one from another.
>>>>
>>>> Most of implementations of String can be shared by Unbounded_String. This
>>>> is what people do manually all the time converting Unbounded_String to
>>>> String and back.
>>>
>>> No, not really. Most implementations of Root_String'Class could be shared
>>> amongst string types.
>>
>> That would be very inconvenient. Certainly, less class-wide operations are
>> provided better is the design.
> 
> "In"convinient? Why?

Class-wide operations are inefficient, ambiguous, require type casts (and
thus unsafe).

> And in any case, the whole point is to 
> eliminate the requirement to use a single, specific string type for 
> operations that should be generic (generic in the English, not Ada, sense).

And the whole point of keeping operation primitive is to have its interface
generic and the implementation type-specific.

>> The model where operations are primitive has the decisive advantage that
>> the operation can be inherited or overridden in order to provide a more
>> efficient version.
> 
> That wouldn't improve the performance enough to matter. If there is a 
> problem with this scheme, it's that it could be very inefficient. But that's 
> mostly because of the use of dispatching, and that's required for the goal 
> to be reached (for most of the existing predefined operations to have 
> versions that take/return Root_String'Class rather than String). If we can't 
> reach that goal, there is no point to doing this at all.

There will be no dispatching because types are known statically for most
applications. Secondly, even if dispatching is present it is manyfold more
efficient that dispatching within the class-wide bodies per character
basis, which where your proposal leads.

>>> Moreover, there cannot be automatic sharing of operations; that weakens 
>>> the type system. One only wants to share operations that are explicitly 
>>> intended to be shared; that's the point of declaring packages operating on
>>> Root_String'Class rather than some specific type.
>>
>> I don't understand the term "shared operation."
>>
>> If you don't want to provide an implementation you declare the operation
>> abstract. If you don't want an operation in the class, you move it into 
>> the body. Where is a problem?
> 
> As above, it's too much work to extend a type that requires overridding more 
> than a handful of primitives.

String types are library types. You cannot extend String now, so the use
case you are talking about does not exist.

>>> The majority of operations would take Root_String'Class and thus work
>>> on any object. Ones that don't would have been restricted for some good
>>> reason, and would work as now. What's so hard about that?
>>
>> It does not make any sense to me. Consider the operation Append. Which
>> class does it belong to? Does it act on String? Is the argument UCS-2?
> 
> Append takes two operands of Root_String'Class, and returns an 
> Root_String'Class with the type of its first argument. What's the problem?

Append is a procedure. Modifiers of Unbounded_String are in-place
operations, that is the major use case for having Unbounded_String at all.

>>> No, I'm deriving from an abstract type with no representation. There's a
>>> huge difference.
>>
>> No difference whatsoever. We are talking about interfaces. The interface 
>> of Unbounded_String is not the interface of String.
> 
> That's true, but that's a bug. They *should* be the same; only the runtime 
> behavior should differ (when exceptions are raised and the like).

They should not and cannot. The type String cannot have procedure Append
because String size is contracted to be constant. Immutable bounds is the
major use case of String. Mutable bounds is of Unbounded_String. You cannot
have both "same."

>> When you force a set of
>> types to one class you must drop parts of the interfaces uncommon to all
>> members. This is why single parent will never work for any more or less
>> non-trivial set of types. String types and numeric types are such sets. It
>> is not even worth trying. The result is doomed.
> 
> Possibly, but then programming language design in general is doomed. The 
> only solutions that would work are crazily inefficient.

Everything should work exactly so it does now, but without explicit type
conversions.

>>>>> "Unbounded_String" is a container for a
>>>>> Root_String'Class type; it adds unbounded memory management to whatever
>>>>> the string type does. There is no reason that one has to do that as 
>>>>> part of the string abstraction.
>>>>
>>>> But then you necessarily loose all operations String cannot have, e.g.
>>>> Append, Replace, etc. The idea is of course that Unbounded_String,
>>>> Unbounded_Wide_Wide_String, Unbounded_UTF8_String share this interface.
>>>
>>> Ada.Strings.Fixed has all of those operations.
>>
>> Append (S, SUNDANESE_LETTER_KHA);
> 
> Yes, that's good. If the underlying type cannot store the letter, 
> Constraint_Error is raised.

Yes! You want weak typing all the way!

In my system the above will be compile error because

1. String does not have Append;

2. String is Latin-1.
 
> As with all tagged types, you trade-off compile-time checking for 
> generality. You can't have both (I know people try, but they are mad - 
> they'll have just as much luck creating a perpetual motion machine).

I can, this what a proper types system is for. If you don't change the type
system you end up with a weakly typed language, which is where Ada sails to
since 2005.

>>>>> You would have
>>>>> to qualify all string literals in an MD world, and that's something
>>>>> programmers would never tolerate.
>>>>
>>>> Ambiguity of literals can be resolved using preference rules like ones
>>>> invented for Universal_Integer. We could introduce Universal_String etc.
>>>
>>> That doesn't work at all; universal integer only has a preference against
>>> itself. All other types are equal.
>>
>> They will have no literals of their own, in this model.
> 
> They have no literals now, in this model. You're just describing the way 
> things are, and then expect it to work differently.

Yes, a common type hierarchy will make it working differently.

>>> and you'd still have
>>> problems with Wide_Wide_String vs. String.
>>
>> No, because wider literals will go to Wide_String and most wide literal to
>> Wide_Wide_String. The idea is to dissect literals according to the code
>> point planes.
> 
> So the behavior of the program changes when the contents of a string literal 
> changes?

Contents of a literal is the literal itself. That is the meaning of the
word "literal." Yes, if you change the literal the behavior changes.
Compare:

    I : Integer_8 := 100;

vs.

    I : Integer_8 := 100_000;

> No thanks.

After you lumped everything into class-wide operations making it weakly
typed?

>>> They are a prime source of beaujolais effects, which Ada considers
>>> completely unacceptable. (Adding or removing a declaration should never
>>> change a legal program into a different legal program with a different
>>> meaning.)
>>
>> Hierarchies of types are not insulated against each other. You cannot
>> simply add or remove declaration of an operation in the hierarchy. That
>> will lead to changes in the dispatching tables, need to define/override
>> something, if the operation is abstract, which is why freezing rules are
>> here etc.
>>
>> It is the nature of a constraint which is far more important than any
>> "beaujolais effects" - that no dispatch can fail at run-time.
>>
>> All slots of any dispatching table must be statically checked for being
>> either properly inherited or overridden. That *necessarily* requires making
>> something illegal which otherwise would be legal. "No-beaujolais" is a
>> nicety for separate compilation, another is strong typing imperative. I
>> gladly trade former for the latter if necessary.
> 
> In other words, you are willing to weaken Ada's contracts in order to get 
> your supposed "strong typing imperative".

No, it is strengthening of the contracts. You removed beaujolais effects by
weakening the contracts to the point where separately compiled units could
retain their contracts independently. Strengthening may lead to loosing
this property.

> Essentially, in your world, you cannot change a package specification 
> because you cannot know what effect such changes have on clients (clients 
> that you don't know much about).

The effect is exactly known - the clients become illegal. That is the idea
of strong contracts. Instead of keeping clients legal but risking
unanticipated behavioral changes, strong contracts make clients illegal
when there is a possibility of changed behavior. If you can statically
prove that the behavior does not change, there is no need to introduce the
"effect."

> That means that there is no hope for 
> reusable software - the originator of the software has to be able to modify 
> it in order to improve or correct it. If that breaks all clients, then 
> either one can do nothing at all, or people just have to stick to their 
> existing (buggy) versions. Neither is acceptable.

Ada has no support for dynamic linking anyway, so it is how it is right
now. Introducing MD won't make bad any worse.

On the other hand, it is well known that OO interfaces are quite fragile
for dynamic linking with or without MD. But this is another problem, which
must be addressed first, when the type system is OK.

>>> And even if you did, it would be an impracticaly large a data
>>> structure in most cases. (Consider that there are something like 20 
>>> string types in a Root_String'Class model,
>>
>> N is not the total number of related types, N is the depth of the given
>> hierarchy. You will have to map Tag to some dense index in the operation's
>> inheritance path and then go into the array with this index. Raw tag is a
>> poor index.
> 
> But it's all we have. Sure, you can map a tag (this requires a loop, either 
> a brute force lookup or some fancier but much more code-intensive version), 
> but that's going to make dispatching far more expensive. You can't do this 
> mapping at compile-time because what mapping you need depends on the 
> interfaces in use.

I can build a perfect hash at bind/link time when all involved tags become
known.

>>>> (However there are serious problems with implementation of MD which I 
>>>> have no idea how to resolve. MI is much simpler)
>>>
>>> I suppose MI is simpler, but it has a similar problem with tag 
>>> construction.
>>> (At least there is only one dimension for interfaces; full MI would turn
>>> things into a much worse situation, as hidden types would have to be
>>> allowed - and then its possible for a type to have multiple copies of the
>>> same interface.)
>>
>> That is a highly desired effect: to support additive model of inheritance.
>> E.g. additive MI from doubly-linked list element.
> 
> It doesn't work, though, because you have to know *which* copy of the 
> interface you are dispatching through.

Operations will be renamed in order to have it unambiguous. It was always
my desire that Ada would require renaming in all cases when something gets
hidden.

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

  reply	other threads:[~2014-04-09 10:40 UTC|newest]

Thread overview: 240+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-25 21:41 Your wish list for Ada 202X Stoik
2014-03-25 22:14 ` Simon Wright
2014-03-26  6:25 ` Shark8
2014-03-26 20:41   ` Randy Brukardt
2014-03-27  9:20     ` Shark8
2014-03-27 21:50       ` Randy Brukardt
2014-03-28  1:54         ` Jeffrey Carter
2014-03-28  8:17         ` Dmitry A. Kazakov
2014-03-28 21:27           ` Randy Brukardt
2014-03-29  9:44             ` Dmitry A. Kazakov
2014-03-31 23:55               ` Randy Brukardt
2014-04-01  8:20                 ` Dmitry A. Kazakov
2014-04-01 10:51                   ` G.B.
2014-04-01 12:40                     ` Dmitry A. Kazakov
2014-04-02 22:39                   ` Randy Brukardt
2014-04-03  2:59                     ` Shark8
2014-04-05 11:10                     ` Dmitry A. Kazakov
2014-04-08  1:15                       ` Randy Brukardt
2014-04-08  9:15                         ` Dmitry A. Kazakov
2014-04-08 10:15                           ` G.B.
2014-04-08 10:56                             ` Dmitry A. Kazakov
2014-04-08 23:37                           ` Randy Brukardt
2014-04-09 10:40                             ` Dmitry A. Kazakov [this message]
2014-04-10  3:28                               ` Randy Brukardt
2014-04-10  8:42                                 ` Georg Bauhaus
2014-04-10 21:52                                   ` Randy Brukardt
2014-04-10 15:31                                 ` Dmitry A. Kazakov
2014-04-10 22:08                                   ` Randy Brukardt
2014-04-11  6:20                                     ` Dmitry A. Kazakov
2014-04-11 21:34                                       ` Randy Brukardt
2014-04-10 22:39                                   ` Randy Brukardt
2014-04-11  6:40                                     ` Dmitry A. Kazakov
2014-04-11 21:44                                       ` Randy Brukardt
2014-04-12  8:45                                         ` Dmitry A. Kazakov
2014-04-14 23:39                                           ` Randy Brukardt
2014-04-15  7:55                                             ` Dmitry A. Kazakov
2014-04-15 21:27                                               ` Randy Brukardt
2014-04-16  7:52                                                 ` Dmitry A. Kazakov
2014-04-16 21:53                                                   ` Randy Brukardt
2014-04-17  7:39                                                     ` Dmitry A. Kazakov
2014-04-17 17:29                                                       ` Randy Brukardt
2014-04-17 19:54                                                         ` Dmitry A. Kazakov
2014-04-11 19:04                                   ` Niklas Holsti
2014-04-11 20:43                                     ` Dmitry A. Kazakov
2014-04-11 22:04                                       ` Niklas Holsti
2014-04-12  8:20                                         ` Dmitry A. Kazakov
2014-04-12  8:39                                           ` Nasser M. Abbasi
2014-04-12  9:38                                             ` Dmitry A. Kazakov
2014-04-12  9:55                                               ` Georg Bauhaus
2014-04-12 10:45                                                 ` Dmitry A. Kazakov
2014-04-14 23:45                                                   ` Randy Brukardt
2014-04-12 10:17                                               ` Nasser M. Abbasi
2014-04-12 10:48                                                 ` Dmitry A. Kazakov
2014-04-13 19:43                                           ` Niklas Holsti
2014-04-13 21:07                                             ` Dmitry A. Kazakov
2014-04-18 19:10                                               ` Niklas Holsti
2014-04-18 21:18                                                 ` Dmitry A. Kazakov
2014-04-19  7:35                                                   ` Niklas Holsti
2014-04-19  8:19                                                     ` Dmitry A. Kazakov
2014-04-19  8:39                                                       ` Dmitry A. Kazakov
2014-04-19  9:08                                                         ` Niklas Holsti
2014-04-19 10:06                                                           ` Dmitry A. Kazakov
2014-04-19 13:53                                                             ` Niklas Holsti
2014-04-19 14:21                                                               ` Dmitry A. Kazakov
2014-04-19 18:28                                                                 ` Niklas Holsti
2014-04-19  9:05                                                       ` Niklas Holsti
2014-04-19 10:18                                                         ` Dmitry A. Kazakov
2014-04-15  0:08                                             ` Randy Brukardt
2014-04-15  7:21                                               ` Natasha Kerensikova
2014-04-15 21:20                                                 ` Randy Brukardt
2014-04-16  6:32                                                 ` Niklas Holsti
2014-04-16  7:24                                                   ` Natasha Kerensikova
2014-04-16  7:31                                                   ` Dmitry A. Kazakov
2014-04-16  9:30                                                   ` Redispatching (was: Your wish list for Ada 202X) J-P. Rosen
2014-04-16 19:53                                                     ` Redispatching Niklas Holsti
2014-04-17  7:26                                                       ` Redispatching Dmitry A. Kazakov
2014-04-17  8:22                                                         ` Redispatching Georg Bauhaus
2014-04-18 20:08                                                         ` Redispatching Niklas Holsti
2014-04-18 20:51                                                           ` Redispatching Dmitry A. Kazakov
2014-04-19  9:17                                                             ` Redispatching Georg Bauhaus
2014-04-19 10:58                                                               ` Redispatching Dmitry A. Kazakov
2014-04-19 11:21                                                                 ` Redispatching Georg Bauhaus
2014-04-17  8:53                                                       ` Redispatching J-P. Rosen
2014-04-16 21:44                                               ` Your wish list for Ada 202X Niklas Holsti
2014-04-16 22:27                                                 ` Randy Brukardt
2014-04-18 19:59                                                   ` Niklas Holsti
2014-04-18 21:28                                                     ` Randy Brukardt
2014-04-19  8:14                                                       ` Niklas Holsti
2014-04-21 23:09                                                         ` Randy Brukardt
2014-04-22  6:08                                                           ` Niklas Holsti
2014-04-22  8:02                                                           ` Dmitry A. Kazakov
2014-04-22  8:30                                                             ` Shark8
2014-04-22  9:14                                                               ` Dmitry A. Kazakov
2014-04-22 23:23                                                                 ` Randy Brukardt
2014-04-23  7:45                                                                   ` Dmitry A. Kazakov
2014-04-23 19:43                                                                     ` Shark8
2014-04-23 20:00                                                                       ` Dmitry A. Kazakov
2014-04-23 21:28                                                                         ` Shark8
2014-04-24  7:30                                                                           ` Dmitry A. Kazakov
2014-04-24 15:20                                                                             ` Shark8
2014-04-24 16:19                                                                               ` Dmitry A. Kazakov
2014-04-24 16:50                                                                                 ` Shark8
2014-04-24 16:57                                                                                   ` Dmitry A. Kazakov
2014-04-19 10:02                                                       ` Georg Bauhaus
2014-03-27 22:06       ` Randy Brukardt
2014-03-28  5:23         ` Shark8
2014-03-26  8:17 ` Dmitry A. Kazakov
2014-03-26  9:02   ` J Kimball
2014-03-26  9:27     ` Dmitry A. Kazakov
2014-03-26 10:30       ` Marius Amado-Alves
2014-03-26 15:11         ` G.B.
2014-03-26 21:55       ` Simon Clubley
2014-03-26 15:03     ` G.B.
2014-03-26 22:00     ` Simon Clubley
2014-03-26 16:01   ` Anh Vo
2014-03-26 17:04     ` Dmitry A. Kazakov
2014-03-27 15:03       ` Dan'l Miller
2014-03-27 16:02         ` Dmitry A. Kazakov
2014-03-26 16:17   ` Stoik
2014-03-26 17:15     ` Dmitry A. Kazakov
2014-03-26 18:04     ` G.B.
2014-03-26 18:47       ` Simon Wright
2014-03-26 19:51         ` Georg Bauhaus
2014-03-27 14:43       ` Jacob Sparre Andersen
2014-03-27 22:50         ` Randy Brukardt
2014-03-28  5:22           ` J-P. Rosen
2014-03-28  7:54           ` Jacob Sparre Andersen
2014-03-28 21:22             ` Randy Brukardt
2014-03-26 21:06     ` Randy Brukardt
2014-03-26 23:15       ` J Kimball
2014-03-27  8:26       ` Dmitry A. Kazakov
2014-03-27 10:54         ` Georg Bauhaus
2014-03-27 15:42           ` Dmitry A. Kazakov
2014-03-27 21:35         ` Randy Brukardt
2014-04-29 14:26       ` Tero Koskinen
2014-04-29 15:39         ` Dan'l Miller
2014-04-29 17:10         ` Simon Clubley
2014-04-29 17:13           ` Tero Koskinen
2014-04-29 19:42             ` Simon Clubley
2014-03-30 12:28 ` francois_fabien
2014-03-30 13:40   ` Luke A. Guest
2014-03-30 14:24     ` Simon Clubley
2014-03-30 18:48       ` Luke A. Guest
2014-03-30 19:22         ` Dmitry A. Kazakov
2014-03-30 14:28     ` Simon Clubley
2014-03-30 15:14       ` Peter Chapin
2014-03-30 18:48         ` Luke A. Guest
2014-03-30 18:48       ` Luke A. Guest
2014-03-30 23:41         ` Simon Clubley
2014-03-31 15:39     ` Adam Beneschan
2014-03-30 13:46   ` Simon Clubley
2014-03-30 19:02   ` Pascal Obry
2014-03-30 19:33     ` Dmitry A. Kazakov
2014-03-30 19:59       ` Pascal Obry
2014-03-31 15:13         ` Stoik
2014-03-31 16:22           ` Pascal Obry
2014-03-31 16:47           ` Pascal Obry
2014-03-31 18:59           ` Dmitry A. Kazakov
2014-04-05  8:28       ` Pascal Obry
2014-04-05 11:06         ` Georg Bauhaus
2014-04-05 11:20           ` Pascal Obry
2014-04-02 16:21 ` Britt
2014-04-02 22:53   ` Randy Brukardt
2014-04-03  0:01     ` Jeffrey Carter
2014-04-03  5:51       ` Pascal Obry
2014-04-03  6:27         ` Jeffrey Carter
2014-04-03 17:18           ` Pascal Obry
2014-04-03 19:11             ` Dan'l Miller
2014-04-03 19:18             ` Dan'l Miller
2014-04-03 21:17             ` Randy Brukardt
2014-04-04  0:29               ` Jeffrey Carter
2014-04-04  8:20                 ` Stefan.Lucks
2014-04-04 19:52                   ` J Kimball
2014-04-04 20:43                     ` Randy Brukardt
2014-04-04 20:54                       ` Shark8
2014-04-04 21:47                       ` Luke A. Guest
2014-04-08  0:47                         ` Randy Brukardt
2014-04-08  4:43                           ` J Kimball
2014-04-08  5:25                             ` Jeffrey Carter
2014-04-08 23:44                             ` Randy Brukardt
2014-04-04 20:53                 ` Randy Brukardt
2014-04-04 23:25                   ` Jeffrey Carter
2014-04-03  6:30         ` Georg Bauhaus
2014-04-03  0:06     ` Britt
2014-04-03 15:15   ` Robert A Duff
2014-04-03 20:19     ` Qun-Ying
2014-04-03 22:56       ` Robert A Duff
2014-04-04 18:31 ` Dan'l Miller
2014-04-04 21:08   ` Randy Brukardt
2014-04-05  3:39   ` Peter Chapin
2014-04-04 20:27 ` Shark8
2014-04-14  4:59 ` J Kimball
2014-04-14  6:54   ` Shark8
2014-04-15  0:22     ` Randy Brukardt
2014-04-15  0:18   ` Randy Brukardt
2014-04-15  5:28     ` J Kimball
2014-04-14 22:36 ` Shark8
2014-04-15  8:41   ` J-P. Rosen
2014-04-18  0:55 ` Robert Love
2014-04-18 11:39   ` Simon Wright
2014-04-23 12:55 ` björn lundin
2014-04-23 13:57   ` J-P. Rosen
2014-04-23 14:32     ` björn lundin
2014-04-23 15:43       ` J-P. Rosen
2014-04-23 16:31         ` björn lundin
2014-04-23 16:42           ` J-P. Rosen
2014-04-23 17:51             ` björn lundin
2014-04-23 21:29               ` Pascal Obry
2014-04-23 22:00                 ` J-P. Rosen
2014-04-23 23:48                   ` Shark8
2014-04-24  5:28                     ` J-P. Rosen
2014-04-23 20:11             ` Randy Brukardt
2014-04-23 20:03           ` Randy Brukardt
2014-04-24  9:08             ` björn lundin
2014-04-23 18:02         ` Jeffrey Carter
2014-04-23 20:14           ` Randy Brukardt
2014-04-24  9:16             ` björn lundin
2014-04-24 11:33               ` G.B.
2014-04-24 12:11                 ` björn lundin
2014-04-24 12:32                   ` G.B.
2014-04-23 14:38     ` Dmitry A. Kazakov
2014-04-23 15:46       ` J-P. Rosen
2014-04-23 16:27         ` Dmitry A. Kazakov
2014-04-23 16:40           ` J-P. Rosen
2014-04-23 17:39             ` Dmitry A. Kazakov
2014-04-23 21:40               ` J-P. Rosen
2014-04-24  7:42                 ` Dmitry A. Kazakov
2014-04-24  9:18                   ` J-P. Rosen
2014-04-23 14:06   ` Dmitry A. Kazakov
2014-04-23 14:44     ` björn lundin
2014-04-23 20:28       ` Randy Brukardt
2014-04-24 10:31         ` björn lundin
2014-04-25  1:22           ` Randy Brukardt
2014-04-25  2:19             ` Shark8
2014-04-25  7:31               ` Dmitry A. Kazakov
2014-04-23 14:58     ` björn lundin
2014-04-23 18:05   ` Jeffrey Carter
2014-04-23 19:48   ` Shark8
2014-04-24  9:03     ` G.B.
2014-04-25  1:27       ` 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