comp.lang.ada
 help / color / mirror / Atom feed
From: ytomino <aghia05@gmail.com>
Subject: Re: discriminant questions
Date: Mon, 19 Sep 2011 10:49:18 -0700 (PDT)
Date: 2011-09-19T10:49:18-07:00	[thread overview]
Message-ID: <be4ed937-6444-463a-8893-daa84e1fa6b6@n40g2000yqb.googlegroups.com> (raw)
In-Reply-To: 1kx7ltnsal62q.195k449mr947t.dlg@40tude.net

> The relevant part is probably 12.5.1(14):
> "The subtype of each discriminant of the actual type shall statically match
> the subtype of the corresponding discriminant of the formal type."
> which I read as *no formal generic discriminants*. I.e. if "statically
> match" means what I think, then "element" in
>    type ref (element : not null access e) is private;
> cannot be matched because "e" is a formal generic parameter.

Thanks. Yes, I did grep RM just now and found the definition of
"statically match". It's written in 4.9.1:

* both are null constraints;
* both are static and have equal corresponding bounds or discriminant
values;
* both are nonstatic and result from the same elaboration of a
constraint of a subtype_indication or the same evaluation of a range
of a discrete_subtype_definition; or
* both are nonstatic and come from the same formal_type_declaration.
<- *A*

4th clause (*A*) is probably applied.
It seems that a formal type is match only itself.
However, it does not explain why does int_ref (having access Integer)
match the_package_use_ref.ref (having access e), since Integer is not
e statically.

(sorry,
> I can not understand the reason that inst1 is error and inst2 is ok.
This is my typo. "inst2 is error and inst3 is ok" is right.)

Should inst3 be error if inst2 is error?

As another reason, if it is disallowed, we can not replace generic
algorithm from Ada 2005 interface to Ada 2012 interface.

for example, from

-- "count" algorithm with Ada 2005 version
generic
   type Element_Type (<>) is private;
   type Cursor is private;
   type Container is private;
   with procedure Iterate (C : Container; Proc : access procedure (P :
Cursor));
   with function Element (P : Cursor) return Element_Type;
procedure Generic_Count (C : Container; Value : Element_Type) return
Count_Type;

to

-- "count" algorithm with Ada 2005 version
generic
   type Element_Type (<>) is private;
   type Cursor is private;
   type Container is private;
   package Iterator_Interfaces is
      new Ada.Iterator_Interfaces (Cursor, others => <>);
   with function Iterate (C : Container)
      return Iterator_Interfaces.Forward_Iterator'Class;
   type Constant_Reference_Type (
      Element : not null access constant Element_Type) with private;
<- *B*
   with function Constant_Reference (C : Container; P : Cursor)
      return Constant_Reference_Type;
procedure Generic_Count (C : Container; Value : Element_Type) return
Count_Type;

There is no way to use a instance of Vectors.Constant_Reference_Type
as *B*.
We have to use Element or Query_Element still in generic.
I feel this is strange and I think designer(s) of new containers did
not intend it.

> As a work-around, make the second package a child or pass the first one as
> a parameter to it.

It means that we have to write plural versions of Generic_Count for
Vectors, for Doubly_Linked_Lists, for Ordered_Sets and more.



  reply	other threads:[~2011-09-19 17:56 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-17 16:30 discriminant questions ytomino
2011-09-17 17:19 ` Dmitry A. Kazakov
2011-09-17 17:46   ` ytomino
2011-09-17 19:41     ` Dmitry A. Kazakov
2011-09-17 22:55       ` ytomino
2011-09-18  8:50         ` Dmitry A. Kazakov
2011-09-18 10:54           ` ytomino
2011-09-18 11:35             ` Dmitry A. Kazakov
2011-09-18 12:41               ` ytomino
2011-09-18 13:17                 ` Dmitry A. Kazakov
2011-09-18 16:22                   ` ytomino
2011-09-18 16:32                   ` ytomino
2011-09-18 18:15                     ` Dmitry A. Kazakov
2011-09-18 23:44                       ` ytomino
2011-09-19  7:27                         ` Dmitry A. Kazakov
2011-09-18 14:43               ` Dmitry A. Kazakov
2011-09-18 16:46               ` Robert A Duff
2011-09-18 18:01                 ` Dmitry A. Kazakov
2011-09-18 19:20                   ` Maciej Sobczak
2011-09-19  7:39                     ` Dmitry A. Kazakov
2011-09-19 20:00                       ` Maciej Sobczak
2011-09-20  7:33                         ` Dmitry A. Kazakov
2011-09-20 15:45                           ` Maciej Sobczak
2011-09-20 16:48                             ` Dmitry A. Kazakov
2011-09-20 20:19                               ` Maciej Sobczak
2011-09-21  7:48                                 ` Dmitry A. Kazakov
2011-09-21 20:51                                   ` Maciej Sobczak
2011-09-22  8:07                                     ` Dmitry A. Kazakov
2011-09-22 20:57                                       ` Maciej Sobczak
2011-09-23  7:59                                         ` Dmitry A. Kazakov
2011-09-23 10:57                                           ` Georg Bauhaus
2011-09-23 22:30                                           ` Randy Brukardt
2011-09-23 22:50                                           ` Randy Brukardt
2011-09-24  6:46                                             ` Dmitry A. Kazakov
2011-09-26 22:48                                               ` Randy Brukardt
2011-09-27  8:10                                                 ` Dmitry A. Kazakov
2011-09-27 10:18                                                   ` Georg Bauhaus
2011-09-27 12:14                                                     ` Dmitry A. Kazakov
2011-09-27 15:11                                                       ` Georg Bauhaus
2011-09-27 15:38                                                         ` Dmitry A. Kazakov
2011-09-27 18:06                                                           ` Georg Bauhaus
2011-09-27 19:06                                                             ` Dmitry A. Kazakov
2011-09-29  0:01                                                               ` Georg Bauhaus
2011-09-29  8:26                                                                 ` Dmitry A. Kazakov
2011-09-30  1:24                                                                   ` Randy Brukardt
2011-09-30  8:10                                                                     ` Dmitry A. Kazakov
2011-09-30 10:07                                                                   ` Georg Bauhaus
2011-09-30 12:38                                                                     ` Dmitry A. Kazakov
2011-09-30 17:40                                                                       ` Georg Bauhaus
2011-09-30 18:55                                                                         ` Dmitry A. Kazakov
2011-09-23  9:23                                       ` Stephen Leake
2011-09-23  9:48                                         ` Dmitry A. Kazakov
2011-09-23 22:42                                           ` Randy Brukardt
2011-09-24  6:56                                             ` Dmitry A. Kazakov
2011-09-26 22:43                                               ` Randy Brukardt
2011-09-24 10:47                                             ` Stephen Leake
2011-09-24 12:54                                       ` Simon Wright
2011-09-24 14:46                                         ` Dmitry A. Kazakov
2011-09-24 16:21                                           ` Simon Wright
2011-09-24 16:43                                             ` Dmitry A. Kazakov
2011-09-22  2:52                                   ` Randy Brukardt
2011-09-22  8:11                                     ` Dmitry A. Kazakov
2011-09-20  0:01           ` Randy Brukardt
2011-09-20  7:38             ` Dmitry A. Kazakov
2011-09-20 11:11               ` AdaMagica
2011-09-20 12:09                 ` Dmitry A. Kazakov
2011-09-20 12:31                   ` AdaMagica
2011-09-20 12:57                     ` Dmitry A. Kazakov
2011-09-20 23:28                       ` ytomino
2011-09-21  5:03                         ` AdaMagica
2011-09-21  8:08                         ` Dmitry A. Kazakov
2011-09-21 10:03                           ` Georg Bauhaus
2011-09-21 10:29                             ` Dmitry A. Kazakov
2011-09-22  3:21                           ` Randy Brukardt
2011-09-22  3:05                   ` Randy Brukardt
2011-09-19 23:35         ` Randy Brukardt
2011-09-20 21:39           ` ytomino
2011-09-22  3:32             ` Randy Brukardt
2011-09-18 16:32 ` ytomino
2011-09-19 14:46   ` ytomino
2011-09-19 15:14     ` Dmitry A. Kazakov
2011-09-19 17:49       ` ytomino [this message]
2011-09-20  7:29         ` Georg Bauhaus
2011-09-20 19:50           ` ytomino
2011-09-20  8:08         ` Dmitry A. Kazakov
2011-09-20 18:47           ` ytomino
2011-09-21  8:16             ` Dmitry A. Kazakov
2011-09-21  9:55               ` ytomino
2011-09-22  3:26                 ` Randy Brukardt
replies disabled

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