Evans@TL-20B.ARPA ("Art Evans") (06/26/87)
Ada does not permit renaming types, the syntax in ARM 8.5 not including any way to do so. In general, the rationale for this lack is that a subtype declaration can be used instead. However, using a subtype does not work in all cases. What I want is something like this: with B; -- Package exporting a type. package A is type T is private; -- A private type. ... private type T renames B.BT; -- Illegal! end A; The renaming declaration is of course illegal. Moreover, the subtype mechanism doesn't help, since there's no such thing as a 'private subtype' declaration and a private type may not be completed with a subtype. I see no clean way out of this problem. The problem can be solved (sort of) by completing the private type declaration with either of type T is record F: B.BT; end record; or type T is access B.BT; I find both of these to be pretty ugly. Either affects all code that uses objects of the type. Has anyone a better solution? This matter looks like a candidate for consideration when Ada is next revised. Art Evans Tartan Labs -------
P9728@QZCOM.MAILNET ("Johan Backlund FOA221") (06/28/87)
Have you tried this form (I guess you haven't...) ? with Export_P; package New_P is type New_T is private; ... private type New_T is new Export_P.Old_T; end New_P; New_T becomes a so called "derived type" and LRM 3.4 tells you all about it. /MtW
emery@MITRE-BEDFORD.ARPA (Emery) (06/29/87)
besides the two possible solutions (record with single component, and access), there's a third possibility: package A is type T is private private type T is new B.BT; end A; However, this introduces all the 'overhead' of derived types. I've often wanted to complete a private type definition as simply another type, so I think this is a real problem, since several people (independently) have identified this shortcoming (see the ACM SIGAda Language Issues WG discussions on this topic). However, I'm not sure that 'rename' is the right operation. It seems to me that 'subtype' may be even better: package A is type T is private; private subtype T is new B.BT; -- possibly constrained, too! end A; dave emery emery@mitre-bedford.arpa
emery@MITRE-BEDFORD.ARPA (Emery) (06/29/87)
Besides the two mechanisms you mentioned, there's a third possibility: type t is new B.BT;
rgs@k.cs.cmu.edu (Robert Stockton) (06/29/87)
Using type derivation to achieve renaming can be effective in some cases, but has its own problems. In particular, it can lead to problems when dealing with multiple types defined in a single package. Consider the following case: package lists is type List is private; type List_Iterator is private; ... function Make_List_Iterator(L : List) return List_Iterator; private ... end lists; with lists; use lists; package rename_lists is type New_List is private; type New_List_Iterator is private; private type New_List is new List; type New_List_Iterator is new List_Iterator; end rename_lists; At this point we have derived functions function Make_List_Iterator(L : List) return New_List_Iterator; function Make_List_Iterator(L : New_List) return List_Iterator; Unfortunately, the one we are likely to want to use is function Make_List_Iterator(L : New_List) return New_List_Iterator; which is not defined. The only way to make use of the derived function is to employ an explicit type conversion, which seems unreasonable in this case. I would be quite pleased if someone could prove me wrong on this point. Am I missing something? -Robert Stockton rgs@spice.cs.cmu.edu ...!seismo!cmu-cs-k!rgs