From: Georg Bauhaus <bauhaus@futureapps.de>
Subject: Re: Subtype conformance... not what I was expecting.
Date: Wed, 26 Jul 2006 10:06:28 +0200
Date: 2006-07-26T10:06:01+02:00 [thread overview]
Message-ID: <1153901187.9300.17.camel@localhost.localdomain> (raw)
In-Reply-To: <44c6db66$0$2928$4d3efbfe@news.sover.net>
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
next prev parent reply other threads:[~2006-07-26 8:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-26 3:02 Subtype conformance... not what I was expecting Peter C. Chapin
2006-07-26 6:58 ` Craig Carey
2006-07-26 7:54 ` Dmitry A. Kazakov
2006-07-26 14:32 ` Peter C. Chapin
2006-07-26 15:38 ` Georg Bauhaus
2006-07-27 0:02 ` Peter C. Chapin
2006-07-26 18:40 ` Dmitry A. Kazakov
2006-07-27 0:00 ` Peter C. Chapin
2006-07-26 8:06 ` Georg Bauhaus [this message]
2006-07-26 14:15 ` Peter C. Chapin
2006-07-26 21:23 ` Adam Beneschan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox