From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada2012 Invariants and obaque types
Date: Tue, 21 Jun 2011 14:31:49 +0200
Date: 2011-06-21T14:31:49+02:00 [thread overview]
Message-ID: <12jyfk40laprz.1mxczd0ze0dr7.dlg@40tude.net> (raw)
In-Reply-To: 4e008bc8$0$6568$9b4e6d93@newsspool3.arcor-online.net
On Tue, 21 Jun 2011 14:17:11 +0200, Georg Bauhaus wrote:
> On 21.06.11 14:08, Dmitry A. Kazakov wrote:
>> On Tue, 21 Jun 2011 01:53:31 -0700 (PDT), Martin wrote:
>>
>>> package P1 is
>>> type T1 is tagged private
>>> with Invariant => Is_Valid (T1);
>>
>> Unrelated to Ada, but in theory, an invariant is a private implementation
>> dependent thing. An invariant is trivially true in all public views of the
>> object, i.e. between any two calls to the object's operations. From that
>> follows, when mentioned in a public part then:
>>
>> type T1 is tagged private with Invariant => True;
>>
>> (Again, I don't know which ideas Ada designers had about invariants, I am
>> not a language lawyer.)
>
> In another theory, the invariant may express things
> such as
> Num_Green_Lights (T1) >= 3;
> or
> 'Length < State_of_Things (T1) * 2;
> where Num_Green_Lights is a publicly visible function whose
> result is somehow computed. These predicates would be informative,
> and formal.
That is not an invariant, but a constraint. Constraint creates a subtype,
it is a type-algebraic operation. Invariant does nothing, it is just a
predicate known to be true for all instances of the type in public
contexts. As such it can be removed any time without changing the program
semantics. A constraint cannot be removed, because its violation is 1)
possible and legal, 2) has defined effect (exception). Violation of an
invariant in public context is impossible in a correct program.
subtype Line is String (1..80); -- 1..80 is a constraint
Line'Length = 80 -- This is an invariant
P.S. Again, no idea how Ada 2012 treats this issue, differently I guess.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2011-06-21 12:31 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-21 8:53 Ada2012 Invariants and obaque types Martin
2011-06-21 10:27 ` Yannick Duchêne (Hibou57)
2011-06-21 10:36 ` Martin
2011-06-21 10:46 ` Martin
2011-06-21 18:42 ` Yannick Duchêne (Hibou57)
2011-06-21 10:43 ` Ludovic Brenta
2011-06-21 10:53 ` Martin
2011-06-21 11:14 ` Martin
2011-06-21 11:31 ` Robert A Duff
2011-06-21 11:48 ` Martin
2011-06-21 12:01 ` Martin
2011-06-21 12:13 ` Robert A Duff
2011-06-21 12:22 ` Martin
2011-06-21 12:54 ` Robert A Duff
2011-06-21 13:00 ` Martin
2011-06-21 12:08 ` Dmitry A. Kazakov
2011-06-21 12:17 ` Georg Bauhaus
2011-06-21 12:31 ` Dmitry A. Kazakov [this message]
2011-06-21 13:29 ` Georg Bauhaus
2011-06-21 14:42 ` Dmitry A. Kazakov
2011-06-21 18:37 ` Yannick Duchêne (Hibou57)
2011-06-21 18:53 ` Dmitry A. Kazakov
2011-06-21 19:34 ` Vinzent Hoefler
2011-06-21 20:52 ` Dmitry A. Kazakov
2011-06-21 21:50 ` Vinzent Hoefler
2011-06-22 7:55 ` Dmitry A. Kazakov
2011-06-21 21:18 ` Manuel Collado
2011-06-22 8:00 ` Dmitry A. Kazakov
2011-06-22 10:39 ` Egil Høvik
2011-06-22 13:57 ` Martin
2011-06-23 16:21 ` anon
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox