From: "Peter C. Chapin" <pchapin@sover.net>
Subject: Re: Subtype conformance... not what I was expecting.
Date: Wed, 26 Jul 2006 10:15:37 -0400
Date: 2006-07-26T10:15:37-04:00 [thread overview]
Message-ID: <44c77904$0$2917$4d3efbfe@news.sover.net> (raw)
In-Reply-To: <1153901187.9300.17.camel@localhost.localdomain>
Georg Bauhaus wrote:
> 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;
In the statement Ice := G(0) you are assigning an Integer to a
Below_Zero. Naturally a runtime check would be necessary to verify the
constraint and Constraint_Error would be raised if there was a
violation. It's no different than
Hot : Integer := 1000;
...
Ice := Hot;
> 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.
G accesses a function returning Integer. Putting Whirl'Access into G is
safe because Whirl can't return anything that would violate G's
contract. What you subsequently do with what G returns is another matter.
Peter
next prev parent reply other threads:[~2006-07-26 14:15 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
2006-07-26 14:15 ` Peter C. Chapin [this message]
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