comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: default formal parameters in generic declarations
Date: Mon, 3 Mar 2008 14:56:31 +0100
Date: 2008-03-03T14:56:31+01:00	[thread overview]
Message-ID: <1qe28uazlamg6.1i48owuthh2b7$.dlg@40tude.net> (raw)
In-Reply-To: 47cbdde1$0$11000$9b4e6d93@newsspool4.arcor-online.net

On Mon, 03 Mar 2008 12:15:45 +0100, Georg Bauhaus wrote:

> Dmitry A. Kazakov schrieb:
> 
>> IMO, it is better (as always) to get rid of generics. Default values of
>> packages are in fact inheritable interfaces. Thus inheritance should be the
>> way. I would extend this part of the language rather than generics.
> 
> Supposedly, removal of generics will also remove the
> tags from concrete types?

Only from non-by-reference ones. Actually Ada already has the keyword
"tagged" which could read "do it by reference and please keep the tag."

> How do you deal with what is now usually a generic
> swap procedure?

type Copyiable is interface ...;
    -- All the things with an assignment and copy constructor (initializer)

A. Class-wide Swap

procedure Swap (Left, Right : in out Copyiable'Class) is
   Temp : Copyiable'Class := Left;
begin
   Left := Right;
   Right := Temp;
end Swap;

B. Primitive Swap (doubly-dispatching with only the diagonal elements
allowed).

procedure Swap (Left, Right : in out Copyiable) is
   Temp : Copyiable'Class := Left;
begin
   Left := Right;
   Right := Temp;
end Swap;

P.S. One problem I didn't know how to solve was the constraints on the
combinations of the argument's types. A generic solution is
pre-constrained, so that it cannot handle some cases at all. For Swap you
might wish to detect all non-diagonal cases which would raise
Constraint_Error at compile time. Clearly, when the tags are known
statically (as with generics) and (for the variant A) the body is inlined,
for the variant B without the body, the compiler could give a warning. The
problem is how to convert warning into an error. I guess that contracted
exceptions could be a solution.

P.P.S. Another problem is adding interfaces to existing types. This is
solved by supertyping.

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



  reply	other threads:[~2008-03-03 13:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-02 17:21 default formal parameters in generic declarations Eric Hughes
2008-03-02 17:42 ` Robert A Duff
2008-03-02 19:40   ` Eric Hughes
2008-03-03  9:17     ` Dmitry A. Kazakov
2008-03-03 11:15       ` Georg Bauhaus
2008-03-03 13:56         ` Dmitry A. Kazakov [this message]
2008-03-04 16:15       ` Eric Hughes
2008-03-04  3:43     ` Randy Brukardt
2008-03-04 16:51       ` Eric Hughes
2008-03-04 18:43         ` Randy Brukardt
2008-03-05 21:08           ` Eric Hughes
2008-03-06  9:32             ` Georg Bauhaus
2008-03-06 18:05               ` Eric Hughes
2008-03-06 22:41                 ` Ludovic Brenta
2008-03-07 10:51                   ` Georg Bauhaus
2008-03-07 20:09                     ` Eric Hughes
2008-03-03 12:42 ` Stephen Leake
2008-03-04 13:50   ` Dr. Adrian Wrigley
2008-03-04 16:56     ` Eric Hughes
2008-03-04 16:44   ` Eric Hughes
2008-03-05 13:11     ` Stephen Leake
2008-03-05 21:41       ` Eric Hughes
replies disabled

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