comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Discriminants of tagged types
Date: Wed, 27 Oct 2010 16:12:42 +0200
Date: 2010-10-27T16:12:42+02:00	[thread overview]
Message-ID: <hidbcwoy5mcn$.1jj3xdnbjhhc8$.dlg@40tude.net> (raw)
In-Reply-To: wcczktzbv4f.fsf@shell01.TheWorld.com

On Wed, 27 Oct 2010 09:52:48 -0400, Robert A Duff wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> On Wed, 27 Oct 2010 05:34:26 -0700 (PDT), Ludovic Brenta wrote:
>>
>>> The tag has no default value and cannot have one, for that would
>>> allow changing the type of an object at run time (through assignment
>>> of an aggregate).
>>
>> No, it would not because you cannot assign a value of another type.
> 
> I think Ludovic means that the Tag could change. That is, tags
> are sort of like discriminants, so if Tags could have defaults,
> then we can guess that they would inherit the strange rule "can change
> if defaulted".  So this would work:
> 
>     A : T1;
>     B : T'Class := A;
>     C : T2;
>     
>     B := C; -- Raises an exception.

But this is an unrelated case. The tag of a specific type cannot be changed
regardless its view as a discriminant.

Considering the class-wide type, its discriminants are unknown, it is an
open set. So the standard rules here do not apply anyway. BTW, if we
considered class-wide assigment dispatchng, we would come to the case of a
specific type when the tags are same, or to Constraint_Error when they
differ.

And independently on defaults:

   A : T1;
   B : T2;
   C : T'Class := A;
   D : T'Class := B;

   C := D;

>>> Therefore, *additional* discriminants cannot have default values either.
>>
>> I think there were concerns about implementation difficulties when the
>> derived type adds new discriminants and/or defines some inherited ones.
>>
>> Anyway the limitation is indeed annoying.
> 
> Then you won't like my opinion, which is that this feature should
> never have existed even for untagged types.  It's useful, but
> it's just not worth the trouble, in terms of programmer confusion,
> and implementation difficulty.  Also nonportability:
> 
>     type T(Length: Natural := 0) is
>         record
>             S: String(1..Length);
>         end record;
> 
> This works on some implementations, and not others.

It might wonder you, but I wholeheartedly agree with you, but for another
reason. The problem default values are supposed to solve IMO, should be
solved by constructors and user-defined aggregates. If they existed and for
any type, the programmer could provide variable list of arguments passed to
the constructor.

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



  reply	other threads:[~2010-10-27 14:12 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-27 12:16 Discriminants of tagged types Maciej Sobczak
2010-10-27 12:34 ` Ludovic Brenta
2010-10-27 13:19   ` Dmitry A. Kazakov
2010-10-27 13:52     ` Robert A Duff
2010-10-27 14:12       ` Dmitry A. Kazakov [this message]
2010-10-27 13:44 ` Robert A Duff
2010-10-27 15:06   ` Adam Beneschan
2010-10-27 15:58     ` Yannick Duchêne (Hibou57)
2010-10-27 16:35       ` Vinzent Hoefler
2010-10-27 17:58       ` J-P. Rosen
2010-10-27 20:18         ` Yannick Duchêne (Hibou57)
2010-10-27 20:26       ` Adam Beneschan
2010-10-27 22:07         ` Yannick Duchêne (Hibou57)
2010-10-27 22:42           ` Adam Beneschan
2010-10-27 15:13   ` Maciej Sobczak
2010-10-27 16:02     ` Yannick Duchêne (Hibou57)
2010-10-27 21:13       ` Maciej Sobczak
2010-10-27 21:23         ` Ludovic Brenta
2010-10-28  8:38           ` Maciej Sobczak
2010-10-27 21:25         ` Vinzent Hoefler
2010-10-28  7:53         ` Dmitry A. Kazakov
2010-10-28  8:50           ` Maciej Sobczak
2010-10-28 10:28             ` Dmitry A. Kazakov
2010-10-28 17:48             ` Yannick Duchêne (Hibou57)
2010-10-29 18:59             ` Vinzent Hoefler
2010-10-30 21:05               ` Maciej Sobczak
2010-10-30 21:21                 ` Vinzent Hoefler
2010-10-30 22:01                   ` Yannick Duchêne (Hibou57)
2010-10-31 16:20                   ` Maciej Sobczak
2010-10-31 17:04                     ` Yannick Duchêne (Hibou57)
2010-10-31 18:36                     ` Shark8
2010-10-31 21:06                       ` Maciej Sobczak
2010-11-01  0:44                         ` Shark8
2010-11-01  9:41                           ` Maciej Sobczak
2010-10-27 16:06     ` Robert A Duff
2010-10-27 16:34       ` Yannick Duchêne (Hibou57)
2010-10-27 21:05       ` Maciej Sobczak
2010-10-28  0:35         ` Robert A Duff
2010-10-28  8:55           ` Maciej Sobczak
2010-10-27 21:28       ` Simon Wright
2010-10-27 13:54 ` J-P. Rosen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox