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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,dad94612ff745427 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news.glorb.com!newsfeed-east.nntpserver.com!nntpserver.com!statler.nntpserver.com!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Instantiating private types with discriminants? Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1147252198.138173.203910@j73g2000cwa.googlegroups.com> <44623869$0$4504$9b4e6d93@newsread2.arcor-online.net> <87d5elk8e9.fsf@ludovic-brenta.org> Date: Thu, 11 May 2006 09:44:20 +0200 Message-ID: NNTP-Posting-Date: 11 May 2006 09:44:18 MEST NNTP-Posting-Host: a8186062.newsread4.arcor-online.net X-Trace: DXC=H]kG[3SaoVQ8f4>W>BJ_OP:ejgIfPPldTjW\KbG]kaMX]kI_X=5KeaVYihOREJ=6OW[6LHn;2LCV^7enW;^6ZC`TIXm65S@:3>_ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:4190 Date: 2006-05-11T09:44:18+02:00 List-Id: On Wed, 10 May 2006 16:52:32 -0500, Rick H wrote: > But all this has a side-effect that I haven't considered: the fact > that a variable declared as a class-wide type *requires* initialization > means that the compiler can determine the variable's type statically. No. It only means that the type should be determinable at run-time. There are may ways to do it. You can call a function with a class-wide result. It might be especially interesting to take a look at S'Class'Input attribute. It "dispatches" on a "bare" tag. [ Ada 2005 will offer a mechanism for fully user-defined things like this. See Generic_Dispatching_Constructor. ] > This means that the following will raise a constraint error: > declare > Var_A : General_T'Class := Get (10); -- Type_A > begin > Put (Var_A); > Ada.Text_IO.New_Line; > Var_A := Get (100.0); -- Type_B - constraint error! > Put (Var_A); > end; Yes, but this is a different thing. You cannot change tag, either dynamically or statically determined. Type mutators are no-no in Ada's type system. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de