comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: Using "with function"
Date: Mon, 29 Oct 2001 12:58:03 -0500
Date: 2001-10-29T12:58:03-05:00	[thread overview]
Message-ID: <ttr5ves1r0m76@corp.supernews.com> (raw)
In-Reply-To: ab21b49a.0107200756.41292cf3@posting.google.com

Actually, this is an interesting question because the generic formal type is
nonlimited -- which means it already comes with a predefined equality
operator.

A rule of thumb for generics is that even for nonlimited types, it's still a
good idea to import the equality operator explicitly.

Also, in general, you should use default notation for generic formal
subprograms, like this:

generic
   type Element_Type is private;
   with function "=" (L, R : Elemenet_Type) return Boolean is <>;  --say "is
box"
package GP is

This simplifies the instantiation, because you don't have to specify the
operation(s) explicitly.

Another thing to think about is that if the equality operator is used only
to implement a single operation (say, this is a container object, with its
own equality operator), then you could defer implementation of the
operation, by moving it to a child:

generic
   type Element_Type is private;
package GP is ...

generic
   with function "=" (L, R : Element_Type) return Boolean is <>;
function GP.Generic_Equality (L, R : Container_Type) return Boolean;

Another question to ask is whether you need assignment of elements.  If not,
then you could declare the generic formal type as limited:

generic
   type Element_Type is limited private;
package GP is ...

This would have the effect of also removing default equality (limited types
don't have predefined equality).

The idea is that for generic formals, you want to require as little from
your client as possible.  I call this (after Deitel) the "principle of least
committment."

Regards,
Matt

"Matt Raikes" <mraikes@vt.edu> wrote in message
news:ab21b49a.0107200756.41292cf3@posting.google.com...
> I ran across this in some code I was examining and I have no clue how
> the with function part works or what its purpose is.
>
> generic
>     type Element_Type is private;
>     with function "="( Left, Right: Element_Type ) return Boolean;
>
>
> please help





  parent reply	other threads:[~2001-10-29 17:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-20 15:56 Using "with function" Matt Raikes
2001-07-21  5:21 ` tmoran
2001-07-21 20:30 ` Mark Lundquist
2001-10-29 17:58 ` Matthew Heaney [this message]
2001-10-30 17:49   ` Mark Lundquist
2001-10-30 22:45     ` Steven Deller
2001-11-03  4:15       ` Mark Lundquist
2001-11-03  5:11         ` Computer Language Shootout Eric Merritt
2001-11-03  6:50           ` tmoran
2001-11-03  7:15             ` Al Christians
2001-11-03  8:52           ` martin.m.dowie
2001-11-03 14:04             ` Ted Dennison
2001-11-03 14:24               ` martin.m.dowie
2001-11-03 14:49               ` Larry Kilgallen
2001-11-03 23:03                 ` research@ijs.co.nz
2001-11-04  6:39                   ` tmoran
2001-11-04 13:44                     ` Larry Kilgallen
2001-11-05  0:59                       ` Adrian Hoe
2001-11-05  8:04                       ` David Brown
2001-11-06  6:36                     ` AG
2001-11-06  8:05                       ` tmoran
2001-11-07  8:58                         ` AG
2001-11-06 12:07                       ` Larry Kilgallen
2001-11-07  6:19                       ` Richard Riehle
2001-11-04 15:59             ` Preben Randhol
2001-11-04 20:04               ` martin.m.dowie
2001-10-31  7:00   ` Using "with function" Richard Riehle
2001-10-31 15:58     ` Matthew Heaney
replies disabled

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