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,628d2a493f1e203d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!news.arcor.de!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Subtype conformance... not what I was expecting. From: Georg Bauhaus In-Reply-To: <44c6db66$0$2928$4d3efbfe@news.sover.net> References: <44c6db66$0$2928$4d3efbfe@news.sover.net> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: # Message-ID: <1153901187.9300.17.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Date: Wed, 26 Jul 2006 10:06:28 +0200 NNTP-Posting-Date: 26 Jul 2006 10:06:01 MEST NNTP-Posting-Host: 2f8041ae.newsread2.arcor-online.net X-Trace: DXC=7\FkDTNof>GUhhl_USDNiOQ5U85hF6f;DjW\KbG]kaMHU7^]5?JhlBNHSQjLSZO8e@PCY\c7>ejVHEU9hbkb\0CAn4HjUacX8FI X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:5928 Date: 2006-07-26T10:06:01+02:00 List-Id: On Tue, 2006-07-25 at 23:02 -0400, Peter C. Chapin wrote: > procedure Check is > subtype Narrow is Integer range -10..10; > type Function_Ptr is access function(X : Narrow) return Integer; > > function F(Para : Integer) return Narrow is > ... > G : Function_Ptr := F'Access; > The compiler complains about the initialization of G with F'Access > saying that it is not "subtype conformant." ... > However, this seems overly restrictive. Would you still think the same in the following variation? (I don't know the rationale for the restriction but then I wasn't surprised :-) procedure Check is subtype Above_Zero is Integer range 1 .. 95; -- from liquid to for tea subtype Below_Zero is Integer range -100 .. -5; -- really solid type Frozen_Ptr is access function(X: Below_Zero) return Integer; type Liquid_Ptr is access function(X: Above_Zero) return Integer; function Whirl(Para: Integer) return Above_Zero is begin return Para; end; function Cut(Para: Integer) return Below_Zero is begin return Para; end; G: Frozen_Ptr := Whirl'access; Ice: Below_Zero; begin Ice := G(0); end Check; Above_Zero and Below_Zero let me think of different logical types, really. The set of values in the respective subtypes is disjoint. I won't want to deliver hot water to/from a function that needs/returns cold ice. In my view, this will be a contract violation, in this case at least. Maybe the restriction helps avoid specimens of "I'm the programmer, and I know that the program is right, even though it's not obvious". -- Georg