From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: troubles learning OOP: expected type "Parent.Some_Child", found type Parent'Class Date: Mon, 12 Feb 2018 19:24:47 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <634e9064-33f8-42c0-9032-e630f98c89d4@googlegroups.com> NNTP-Posting-Host: 9s2HXjYgtb87Rt4JbNw44Q.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.3 Xref: reader02.eternal-september.org comp.lang.ada:50392 Date: 2018-02-12T19:24:47+01:00 List-Id: On 2018-02-12 19:17, Mehdi Saada wrote: > ... Somehow, it doesn't surprise me anymore. > >> Get_Elem take T_Token'Class > How could I do that, since it meant to RETURN a different type for each subclass ! 1. Class /= type. Class is a set of types rooted in a type. 2. T'Class is meant to have values of/equivalent to values of all these different types. 3. You can always convert a member of the class (a specific type) to the class-wide type of any class this specific type belongs to. type T is ...; type S is new T with ...; function Foo return T'Class is Result : S; begin return T'Class (Result); -- This is OK end Foo; > Now, I know why I prefered mutant types even before using them. Mutable instances are always less safe than immutable ones. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de