* 'Class'Class'Class'Class ad libitum @ 2016-09-13 10:43 Alejandro R. Mosteo 2016-09-13 11:29 ` J-P. Rosen 2016-09-13 12:37 ` Dmitry A. Kazakov 0 siblings, 2 replies; 9+ messages in thread From: Alejandro R. Mosteo @ 2016-09-13 10:43 UTC (permalink / raw) I get why this is legal: type X is tagged null record; subtype Y is X'Class; subtype Z is X'Class'Class'Class'Class; But can you think of any legitimate reason to use it besides obfuscation? Álex ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: 'Class'Class'Class'Class ad libitum 2016-09-13 10:43 'Class'Class'Class'Class ad libitum Alejandro R. Mosteo @ 2016-09-13 11:29 ` J-P. Rosen 2016-09-13 16:10 ` Alejandro R. Mosteo 2016-09-13 18:53 ` Robert A Duff 2016-09-13 12:37 ` Dmitry A. Kazakov 1 sibling, 2 replies; 9+ messages in thread From: J-P. Rosen @ 2016-09-13 11:29 UTC (permalink / raw) Le 13/09/2016 à 12:43, Alejandro R. Mosteo a écrit : > I get why this is legal: > > type X is tagged null record; > > subtype Y is X'Class; > > subtype Z is X'Class'Class'Class'Class; > > But can you think of any legitimate reason to use it besides obfuscation? > I guess this is allowed because nobody cared about complicated rules to forbid it (mainly on the ground that it's useless, but harmless). There are many things like that: T'(T'(T'(X))) X+0+0+0 ... -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: 'Class'Class'Class'Class ad libitum 2016-09-13 11:29 ` J-P. Rosen @ 2016-09-13 16:10 ` Alejandro R. Mosteo 2016-09-13 18:53 ` Robert A Duff 1 sibling, 0 replies; 9+ messages in thread From: Alejandro R. Mosteo @ 2016-09-13 16:10 UTC (permalink / raw) On 13/09/16 13:29, J-P. Rosen wrote: > Le 13/09/2016 à 12:43, Alejandro R. Mosteo a écrit : >> I get why this is legal: >> >> type X is tagged null record; >> >> subtype Y is X'Class; >> >> subtype Z is X'Class'Class'Class'Class; >> >> But can you think of any legitimate reason to use it besides obfuscation? >> > I guess this is allowed because nobody cared about complicated rules to > forbid it (mainly on the ground that it's useless, but harmless). There > are many things like that: > T'(T'(T'(X))) > X+0+0+0 > ... I like the qualified expression one... ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: 'Class'Class'Class'Class ad libitum 2016-09-13 11:29 ` J-P. Rosen 2016-09-13 16:10 ` Alejandro R. Mosteo @ 2016-09-13 18:53 ` Robert A Duff 1 sibling, 0 replies; 9+ messages in thread From: Robert A Duff @ 2016-09-13 18:53 UTC (permalink / raw) "J-P. Rosen" <rosen@adalog.fr> writes: > I guess this is allowed because nobody cared about complicated rules to > forbid it (mainly on the ground that it's useless, but harmless). I think it was to make this work: generic type Formal (<>) is tagged private; package G is pragma Elaborate_Body; end G; package body G is subtype S is Formal'Class; end G; with G; package P is type T is tagged null record; package Inst is new G (Formal => T'Class); end P; We don't want the legality of an instance to depend on the contents of the generic body. > ...There > are many things like that: > T'(T'(T'(X))) > X+0+0+0 > ... - Bob ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: 'Class'Class'Class'Class ad libitum 2016-09-13 10:43 'Class'Class'Class'Class ad libitum Alejandro R. Mosteo 2016-09-13 11:29 ` J-P. Rosen @ 2016-09-13 12:37 ` Dmitry A. Kazakov 2016-09-13 16:10 ` Alejandro R. Mosteo 1 sibling, 1 reply; 9+ messages in thread From: Dmitry A. Kazakov @ 2016-09-13 12:37 UTC (permalink / raw) On 13/09/2016 12:43, Alejandro R. Mosteo wrote: > I get why this is legal: > > type X is tagged null record; > > subtype Y is X'Class; > > subtype Z is X'Class'Class'Class'Class; > > But can you think of any legitimate reason to use it besides obfuscation? Only the latter is wrong. X'Class'Class cannot be same as X'Class. X is a set of values with operations on X X'Class is a set of values of X and values of all types derived from X X'Class'Class should be a set of values of X'Class and values of all types derived from X'Class. We cannot derive from X'Class in Ada, so class of X'Class holds only X'Class. But that does not make them same. Like X is not same as X'Class even if there is no descendants of X. Class-wide operations of X would be primitive operations of X'Class'Class. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: 'Class'Class'Class'Class ad libitum 2016-09-13 12:37 ` Dmitry A. Kazakov @ 2016-09-13 16:10 ` Alejandro R. Mosteo 2016-09-13 16:34 ` Dmitry A. Kazakov 0 siblings, 1 reply; 9+ messages in thread From: Alejandro R. Mosteo @ 2016-09-13 16:10 UTC (permalink / raw) On 13/09/16 14:37, Dmitry A. Kazakov wrote: > On 13/09/2016 12:43, Alejandro R. Mosteo wrote: >> I get why this is legal: >> >> type X is tagged null record; >> >> subtype Y is X'Class; >> >> subtype Z is X'Class'Class'Class'Class; >> >> But can you think of any legitimate reason to use it besides obfuscation? > > Only the latter is wrong. X'Class'Class cannot be same as X'Class. > > X is a set of values with operations on X > > X'Class is a set of values of X and values of all types derived from X > > X'Class'Class should be a set of values of X'Class and values of all > types derived from X'Class. We cannot derive from X'Class in Ada, so > class of X'Class holds only X'Class. But that does not make them same. > Like X is not same as X'Class even if there is no descendants of X. > Class-wide operations of X would be primitive operations of X'Class'Class. I see that from a strict theoretic POV. However, that's not the interpretation that current Ada grammar does, right? Actually I arrived at this because I am somewhat wary of the fact that using a subtype like Y in my example hides the fact to the reader that the type is class-wide and hence dispatching by default. Furthermore, you can legally write procedure Blah (This : Other_Package.Y); -- or procedure Blah (This : Other_Package.Y'Class); and AFAIK that's totally equivalent but the former is less informative (and alas, shorter to write). First time I wrote the later I expected to get an error or warning of the short "subtype is already class-wide". Álex. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: 'Class'Class'Class'Class ad libitum 2016-09-13 16:10 ` Alejandro R. Mosteo @ 2016-09-13 16:34 ` Dmitry A. Kazakov 2016-09-13 16:54 ` Alejandro R. Mosteo 0 siblings, 1 reply; 9+ messages in thread From: Dmitry A. Kazakov @ 2016-09-13 16:34 UTC (permalink / raw) On 2016-09-13 18:10, Alejandro R. Mosteo wrote: > On 13/09/16 14:37, Dmitry A. Kazakov wrote: >> On 13/09/2016 12:43, Alejandro R. Mosteo wrote: >>> I get why this is legal: >>> >>> type X is tagged null record; >>> >>> subtype Y is X'Class; >>> >>> subtype Z is X'Class'Class'Class'Class; >>> >>> But can you think of any legitimate reason to use it besides >>> obfuscation? >> >> Only the latter is wrong. X'Class'Class cannot be same as X'Class. >> >> X is a set of values with operations on X >> >> X'Class is a set of values of X and values of all types derived from X >> >> X'Class'Class should be a set of values of X'Class and values of all >> types derived from X'Class. We cannot derive from X'Class in Ada, so >> class of X'Class holds only X'Class. But that does not make them same. >> Like X is not same as X'Class even if there is no descendants of X. >> Class-wide operations of X would be primitive operations of >> X'Class'Class. > > I see that from a strict theoretic POV. However, that's not the > interpretation that current Ada grammar does, right? Semantics you mean. That semantics is wrong. If T'Class'Class is legal, I don't know. It should not be otherwise than in the described above sense. > Actually I arrived at this because I am somewhat wary of the fact that > using a subtype like Y in my example hides the fact to the reader that > the type is class-wide and hence dispatching by default. Dispatching is a property of an operation's argument, not of a type. The same object may dispatch or not. It should not be reader's concern. Dispatching is merely a method of operation implementation, that is by composition of the operation body out of multiple bodies of other operations selected by the tag. It is a pure implementation detail. > Furthermore, > you can legally write > > procedure Blah (This : Other_Package.Y); -- or > procedure Blah (This : Other_Package.Y'Class); > > and AFAIK that's totally equivalent but the former is less informative > (and alas, shorter to write). From the original Ada POV the former is better. Initially Ada strove to have nominal typing. T'Class notation parts with that, it is structural equivalence, which is not that great. > First time I wrote the later I expected to > get an error or warning of the short "subtype is already class-wide". A good catch by compiler. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: 'Class'Class'Class'Class ad libitum 2016-09-13 16:34 ` Dmitry A. Kazakov @ 2016-09-13 16:54 ` Alejandro R. Mosteo 2016-09-13 18:41 ` Dmitry A. Kazakov 0 siblings, 1 reply; 9+ messages in thread From: Alejandro R. Mosteo @ 2016-09-13 16:54 UTC (permalink / raw) On 13/09/16 18:34, Dmitry A. Kazakov wrote: > On 2016-09-13 18:10, Alejandro R. Mosteo wrote: >> On 13/09/16 14:37, Dmitry A. Kazakov wrote: >>> On 13/09/2016 12:43, Alejandro R. Mosteo wrote: >>>> I get why this is legal: >>>> >>>> type X is tagged null record; >>>> >>>> subtype Y is X'Class; >>>> >>>> subtype Z is X'Class'Class'Class'Class; >>>> >>>> But can you think of any legitimate reason to use it besides >>>> obfuscation? >>> >>> Only the latter is wrong. X'Class'Class cannot be same as X'Class. >>> >>> X is a set of values with operations on X >>> >>> X'Class is a set of values of X and values of all types derived from X >>> >>> X'Class'Class should be a set of values of X'Class and values of all >>> types derived from X'Class. We cannot derive from X'Class in Ada, so >>> class of X'Class holds only X'Class. But that does not make them same. >>> Like X is not same as X'Class even if there is no descendants of X. >>> Class-wide operations of X would be primitive operations of >>> X'Class'Class. >> >> I see that from a strict theoretic POV. However, that's not the >> interpretation that current Ada grammar does, right? > > Semantics you mean. That semantics is wrong. If T'Class'Class is legal, > I don't know. It should not be otherwise than in the described above sense. > >> Actually I arrived at this because I am somewhat wary of the fact that >> using a subtype like Y in my example hides the fact to the reader that >> the type is class-wide and hence dispatching by default. > > Dispatching is a property of an operation's argument, not of a type. The > same object may dispatch or not. It should not be reader's concern. > Dispatching is merely a method of operation implementation, that is by > composition of the operation body out of multiple bodies of other > operations selected by the tag. It is a pure implementation detail. True, but the reader/user needs to make explicit the class-wideness of a value if dispatching is desired (and conversely), and this can lead to errors. GPS nowadays highlights dispatching calls... > >> Furthermore, >> you can legally write >> >> procedure Blah (This : Other_Package.Y); -- or >> procedure Blah (This : Other_Package.Y'Class); >> >> and AFAIK that's totally equivalent but the former is less informative >> (and alas, shorter to write). > > From the original Ada POV the former is better. Initially Ada strove to > have nominal typing. T'Class notation parts with that, it is structural > equivalence, which is not that great. Interesting. > >> First time I wrote the later I expected to >> get an error or warning of the short "subtype is already class-wide". > > A good catch by compiler. That Gnat does not perform ;) ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: 'Class'Class'Class'Class ad libitum 2016-09-13 16:54 ` Alejandro R. Mosteo @ 2016-09-13 18:41 ` Dmitry A. Kazakov 0 siblings, 0 replies; 9+ messages in thread From: Dmitry A. Kazakov @ 2016-09-13 18:41 UTC (permalink / raw) On 2016-09-13 18:54, Alejandro R. Mosteo wrote: > On 13/09/16 18:34, Dmitry A. Kazakov wrote: >> Dispatching is a property of an operation's argument, not of a type. The >> same object may dispatch or not. It should not be reader's concern. >> Dispatching is merely a method of operation implementation, that is by >> composition of the operation body out of multiple bodies of other >> operations selected by the tag. It is a pure implementation detail. > > True, but the reader/user needs to make explicit the class-wideness of a > value if dispatching is desired (and conversely), and this can lead to > errors. GPS nowadays highlights dispatching calls... No, the reader does not need that. There are language aberrations that allow declaration of non-primitive operations. But from the SW design POV all operations must be always either dispatching or class-wide = acting uniformly on the declared type. You need to know only if the principle gets violated and the operation suddenly does not act as it must. Then you indeed need to know dirty details of the consequences of language limitations. These cases should have been all illegal, but that would require multiple dispatch working. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2016-09-13 18:53 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-09-13 10:43 'Class'Class'Class'Class ad libitum Alejandro R. Mosteo 2016-09-13 11:29 ` J-P. Rosen 2016-09-13 16:10 ` Alejandro R. Mosteo 2016-09-13 18:53 ` Robert A Duff 2016-09-13 12:37 ` Dmitry A. Kazakov 2016-09-13 16:10 ` Alejandro R. Mosteo 2016-09-13 16:34 ` Dmitry A. Kazakov 2016-09-13 16:54 ` Alejandro R. Mosteo 2016-09-13 18:41 ` Dmitry A. Kazakov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox