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=ham 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!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.pipex.net!news.pipex.net.POSTED!not-for-mail NNTP-Posting-Date: Wed, 10 May 2006 16:52:32 -0500 From: Rick H Subject: Re: Instantiating private types with discriminants? Newsgroups: comp.lang.ada References: <1147252198.138173.203910@j73g2000cwa.googlegroups.com> <44623869$0$4504$9b4e6d93@newsread2.arcor-online.net> <87d5elk8e9.fsf@ludovic-brenta.org> Organization: home User-Agent: tin/1.7.8-20050315 ("Scalpay") (UNIX) (Linux/2.6.8-2-686 (i686)) Message-ID: Date: Wed, 10 May 2006 16:52:32 -0500 NNTP-Posting-Host: 85.210.142.64 X-Trace: sv3-IGAGza8FvLE3rKriN6Vj1nblpp0idXPmUVXQKVGlWKBxRVmVgIljo3ZDMXs6CPiA+fguxhzw/JiPFNt!jCfY5KYHZ4I3b+RBADvl8eo0ySajVTNqObbyjqgHu+uzYQ/2NFWSM/4WrDxBpj9seD2gKB4VDzXr!TqUNWIv/XjNS X-Complaints-To: abuse@dsl.pipex.net X-DMCA-Complaints-To: abuse@dsl.pipex.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news2.google.com comp.lang.ada:4187 Date: 2006-05-10T16:52:32-05:00 List-Id: Ludovic Brenta wrote: > Here is a complete, working example, in case you're confused. It > summarises everything we've said before: package (possibly, like here, > nested in the procedure), freezing rules, abstract procedure in the > base type, no access type, and declaring the object at the last > moment. > > Now, can you answer this question: which subprograms in that example > are primitive and which ones are not? > Thanks, Ludovic. I extented your example by parameterising Get and creating two versions: function Get (Item : Integer) return General_T'Class is begin return Type_A' (Data => Item); end Get; function Get (Item : Float) return General_T'Class is begin return Type_B' (Data => Item); end Get; and then Var_A can be declared as either of: Var_A : General_T'Class := Get (10); or Var_A : General_T'Class := Get (10.0); 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. 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;