comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada2012 Invariants and obaque types
Date: Wed, 22 Jun 2011 10:00:47 +0200
Date: 2011-06-22T10:00:47+02:00	[thread overview]
Message-ID: <1il5w6m4gt3xd$.1s01y6lkslfjf.dlg@40tude.net> (raw)
In-Reply-To: itr255$3eq$1@peque.uv.es

On Tue, 21 Jun 2011 23:18:49 +0200, Manuel Collado wrote:

> El 21/06/2011 20:53, Dmitry A. Kazakov escribi�:
>> On Tue, 21 Jun 2011 20:37:44 +0200, Yannick Duch�ne (Hibou57) wrote:
>>
>>> Le Tue, 21 Jun 2011 14:08:15 +0200, Dmitry A. Kazakov
>>> <mailbox@dmitry-kazakov.de>  a �crit:
>>>
>>>> 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 understand the point and had the same first feeling too.
>>
>> The first feeling is always the right one. (:-))
>>
>>> While that's OK
>>> in theory, in practice the user may wish methods to check for validity
>>> rules defined for a type.
>>
>> Validity is a misconception. In a properly typed language any value is
>> valid, that is the property of being typed. A value is invalid when the
>> type system was circumvented, which should never happen publicly.
> 
> Humm... What about an integral type whose set of valid values are the 
> prime numbers (upto some representation limit)?

Prime numbers (as a set) are not numbers (e.g. do not form an additive
group: if p1, p2 are primes, p1 + p2 is not necessarily prime.)

> Common practice is to define such type as Integer, Natural or Positive, 
> and write some validation function to check values at runtime.

To have a publicly integer type of only prime numbers would be a bad idea.

> Or do you mean that Ada is not a properly typed language?

Ada's typing is better than of any other language I know. Yes, it has
issues, especially with construction-destruction of tagged types, nobody is
perfect.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2011-06-22  8:00 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
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 [this message]
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