comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Generic procedures and their parameters
Date: 06 Sep 2006 08:56:35 -0400
Date: 2006-09-06T08:56:35-04:00	[thread overview]
Message-ID: <wccac5dxif0.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: edm273$fee$1@sunnews.cern.ch

Maciej Sobczak <no.spam@no.spam.com> writes:

> Hi,
> 
> I have found the following signature for the sorting procedure:
> 
> eneric
>     type Index_Type   is (<>);
>     type Element_Type is private;
>     type Array_Type   is array (Index_Type range <>) of Element_Type;
>     with function "<" (Left, Right : in Element_Type) return Boolean is <>;
> procedure Sort(To_Sort : in out Array_Type);
> 
> My question is: what's the purpose of the third parameter (Array_Type)?
> Isn't it implied by the first two and therefore just redundant?

Well, if you simply erase the Array_Type formal, then the reference to
Array_Type in the declaration of To_Sort would be in error.
And you cannot say this:

generic
    type Index_Type   is (<>);
    type Element_Type is private;
    with function "<" (Left, Right : in Element_Type) return Boolean is <>;
procedure Sort(To_Sort : in out array (Index_Type range <>) of Element_Type); -- Illegal syntax!

because Ada uses "by name" type equivalence (mostly).  In this case,
structural equivalence might be more convenient.

You could do it this way:

generic
    type Index_Type   is (<>);
    type Element_Type is private;
    with function "<" (Left, Right : in Element_Type) return Boolean is <>;
package Sorting is

    type Array_Type   is array (Index_Type range <>) of Element_Type;
    procedure Sort(To_Sort : in out Array_Type);

end Sorting;

but that's less flexible for the client, because it can't use it's own
array type.

- Bob



  parent reply	other threads:[~2006-09-06 12:56 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-06  8:51 Generic procedures and their parameters Maciej Sobczak
2006-09-06  9:43 ` Dmitry A. Kazakov
2006-09-06 12:36   ` Maciej Sobczak
2006-09-06 13:11     ` Robert A Duff
2006-09-06 14:14       ` Maciej Sobczak
2006-09-06 15:09         ` Dmitry A. Kazakov
2006-09-06 16:35           ` Georg Bauhaus
2006-09-07  7:32             ` Dmitry A. Kazakov
2006-09-07  6:48               ` Georg Bauhaus
2006-09-07 10:19                 ` Dmitry A. Kazakov
2006-09-08  9:11           ` Maciej Sobczak
2006-09-08 10:19             ` Dmitry A. Kazakov
2006-09-09 14:49         ` Robert A Duff
2006-09-09 15:34           ` Dmitry A. Kazakov
2006-09-09 23:26           ` Jeffrey R. Carter
2006-09-10 11:49             ` Robert A Duff
2006-09-10 19:43               ` Jeffrey R. Carter
2006-09-06 13:02   ` Robert A Duff
2006-09-06 14:09     ` Dmitry A. Kazakov
2006-09-08  3:35   ` Randy Brukardt
2006-09-08  7:21     ` Dmitry A. Kazakov
2006-09-09  1:29       ` Randy Brukardt
2006-09-09  7:14         ` Dmitry A. Kazakov
2006-09-09 14:32         ` Robert A Duff
2006-09-06 12:56 ` Robert A Duff [this message]
2006-09-07  2:47 ` Steve
2006-09-07  7:47   ` Dmitry A. Kazakov
replies disabled

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