comp.lang.ada
 help / color / mirror / Atom feed
From: blaak@mda.ca (Ray Blaak)
Subject: Re: parameterless generics?
Date: 1996/07/11
Date: 1996-07-11T00:00:00+00:00	[thread overview]
Message-ID: <4s4sns$nl4@map.mda.ca> (raw)
In-Reply-To: 4s48k9$3be$1@mhafn.production.compuserve.com


Brian Gilbert <71413.1453@CompuServe.COM> writes:

>Does anybody have a reason to use a generic (package or 
>subprogram) without a parameter?  The language (Ada 83 at least) 
>seems to allow it, but everytime the generic is instantiated it 
>would produce an identical copy.  Comments?

I find it useful primarily to give distinct types that cannot legally be
converted to each other.

generic
package Element is
  type Object is private;

  procedure Operation (On_The_Object : in out Object);
private
 type Object is ...;
end Element;

package Node is new Element;
package Symbol is new Element;

Node.Object and Symbol.Object cannot be converted from one to the other,
whereas they could if derived from a common type.

Another possible reason is to make functionality "active" only when you need
it. Consider:

package Entity is
  type Object is private;

  procedure Low_Impact_Operation (On_The_Object : in out Object);

  generic
  package Fancy_Processing_Involving_A_Huge_Link_Enclosure is
    procedure Do_It_At_Your_Own_Risk (To_Me : in out Object);
  end Fancy_Processing_Involving_A_Huge_Link_Enclosure;
end Entity;

It could be that one application (say offline report generation) only needs a
few features and a small link enclosure. The real system might be involved in a
complex architecture with a large link enclosure. By having the extra
operations in a generic, there should be no executable code generated for it
until instantiation. This would be dependent on how you wrote the generic and
how the compiler implements generics.

Cheers,
Ray Blaak
blaak@mda.ca




  parent reply	other threads:[~1996-07-11  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-12  0:00 parameterless generics? Brian Gilbert
1996-07-11  0:00 ` Laurent Guerby
1996-07-11  0:00 ` Ray Blaak [this message]
1996-07-15  0:00   ` Mark A Biggar
1996-07-12  0:00 ` Philip Brashear
1996-07-12  0:00 ` Robert Dewar
1996-07-22  0:00   ` Mats Weber
1996-07-12  0:00 ` Theodore E. Dennison
1996-07-14  0:00 ` Norman H. Cohen
1996-07-15  0:00 ` Chris Papademetrious
1996-07-17  0:00   ` Richard Riehle
1996-07-18  0:00 ` Martin Lorentzon
replies disabled

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