comp.lang.ada
 help / color / mirror / Atom feed
* Re: Limited types
  1998-05-22  0:00 Limited types Phani Putrevu
@ 1998-05-21  0:00 ` Matthew Heaney
  0 siblings, 0 replies; 4+ messages in thread
From: Matthew Heaney @ 1998-05-21  0:00 UTC (permalink / raw)



In article <3564E39E.B8D445B0@ececs.uc.edu>, Phani Putrevu
<pputrevu@ececs.uc.edu> wrote:

(start of quote)
How  exactly is limited type defined.. In the glossary of the on-line
RM, limited type is defined as a type for which the assignment operator
is not defined. What about the equality operator?  In the operators
section,  it is told that equality and inequality operators are
predefined for nonlimited types.  Does this follow from the assignment
operator not being allowed.
(end of quote)

Typically, you'd declare an abstract data type as limited, as in:

   type LT is limited private;

or 

   type LT is tagged limited private;

or

   type LT is abstract tagged limited private;

You can also declare a record as limited:

   type RT is 
      limited record
         ...
      end record;

Limited private types are used when you have an item which it doesn't make
sense to duplicate, ie

   type Bank_Account is tagged limited private;
...
   Matts_Money : Bank_Account;

I would love to be able to do this:

   Matts_Money := Matts_Money + Matts_Money;

but of course I don't think the bank would take too kindly to this sort of
thing!  That's why it's illegal (for limited types).

Equality isn't predefined for a limited type, but you can add one if it
makes sense for your abstraction:

   function "=" (L, R : Bank_Account) return Boolean;

Equality is predefined for a non-limited type.  The default definition is a
bit-wise compare, which very often is _not_ what you want, so even for
non-limited types, you typically override it.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Limited types
@ 1998-05-22  0:00 Phani Putrevu
  1998-05-21  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 4+ messages in thread
From: Phani Putrevu @ 1998-05-22  0:00 UTC (permalink / raw)



Hi,

very basic question :

How  exactly is limited type defined.. In the glossary of the on-line
RM, limited type is defined as a type for which the assignment operator
is not defined. What about the equality operator?  In the operators
section,  it is told that equality and inequality operators are
predefined for nonlimited types.  Does this follow from the assignment
operator not being allowed.

Thanks a lot,

Phani





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: limited types
  2006-02-28 19:58                                 ` Matthew Heaney
@ 2006-02-28 21:51                                   ` Simon Wright
  2006-03-01  1:59                                     ` Matthew Heaney
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Wright @ 2006-02-28 21:51 UTC (permalink / raw)


"Matthew Heaney" <mheaney@on2.com> writes:

> generic
>   type ET is private;  --or: type ET (<>) is limited private;
>   type CT is private;  --cursor type
>   with function E (C : CT) return ET is <>;
> procedure Generic_Algorithm (C1, C2 : CT);
>
> The cursor pair [C1, C2) describes a range of elements.  It might be
> the entire range of elements in the container, or just a subrange.
> The algorithm doesn't care.

I would have expected some operation like Succ on CT? (and equality?
would predefined equality on cursors be OK?)



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: limited types
  2006-02-28 21:51                                   ` limited types Simon Wright
@ 2006-03-01  1:59                                     ` Matthew Heaney
  0 siblings, 0 replies; 4+ messages in thread
From: Matthew Heaney @ 2006-03-01  1:59 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> I would have expected some operation like Succ on CT? 

Yeah, you're right; I forgot to write an ellipsis.  Each algorithm would have
to pass in the requisite element/cursor operations as generic formals.

For a similar idea, see Ada.Containers.Generic_Anonymous_Array_Sort in the GNAT
distribution.


> (and equality?  would predefined equality on cursors be OK?)

The standard container library guarantees that cursor equality composes, so
predefined equality would work fine.  It wouldn't hurt to pass in a default
equality operator, though.  



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-03-01  1:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-22  0:00 Limited types Phani Putrevu
1998-05-21  0:00 ` Matthew Heaney
  -- strict thread matches above, loose matches on Subject: below --
2006-02-24 16:51 limited types (Was: Records that could be arrays) Thierry Bernier
2006-02-24 21:57 ` Randy Brukardt
2006-02-25 11:06   ` Dmitry A. Kazakov
2006-02-25 15:05     ` Matthew Heaney
2006-02-26  9:00       ` Dmitry A. Kazakov
2006-02-26 18:20         ` Matthew Heaney
2006-02-26 20:52           ` Dmitry A. Kazakov
2006-02-26 22:07             ` Matthew Heaney
2006-02-27  9:11               ` Dmitry A. Kazakov
2006-02-27 14:34                 ` Georg Bauhaus
2006-02-27 16:05                   ` Dmitry A. Kazakov
2006-02-27 16:52                     ` Matthew Heaney
2006-02-27 20:21                       ` Dmitry A. Kazakov
2006-02-27 23:00                         ` Matthew Heaney
2006-02-28  9:39                           ` Dmitry A. Kazakov
2006-02-28 17:24                             ` Matthew Heaney
2006-02-28 19:06                               ` Dmitry A. Kazakov
2006-02-28 19:58                                 ` Matthew Heaney
2006-02-28 21:51                                   ` limited types Simon Wright
2006-03-01  1:59                                     ` Matthew Heaney

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