comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst@cts.com>
Subject: Re: Private discrete type as index
Date: Sun, 12 Jan 2003 19:23:38 GMT
Date: 2003-01-12T19:23:38+00:00	[thread overview]
Message-ID: <yecy95qmasf.fsf@king.cts.com> (raw)
In-Reply-To: RKJT9.21144$F63.395685@news.xtra.co.nz

"AG" <ang@xtra.co.nz> writes:
> Guess I have a question that I'm a bit puzzled about.
> Consider the boiled-down code snippet:
> 
> package test is
>   type x is limited private;
>   type test is array(x) of boolean;
> private
>     type x is new boolean;
> end test;
> 
> Trying to compile that fails on GNAT with "Discrete type required"
> error.  Can't blame it, of course, since it's correct according to
> LRM. But...
> 
> the obvious intention was to provide a set of "+/-" operations etc
> on the limited type (which are not trivial) and prevent the
> out-of-package clients from messing with the index.
> 
> Since the compiler obviously knows the implementation details, why
> not?
> 
> Of course, it can be implemented as an iterator, but what's wrong
> with the example as written? After all, the client modules can't use
> that index other than through the type and operation provided by the
> package. Compiler/linker sure knows what the type is. So, why not?

I think you really want to overload the array indexing operation.  Ada
doesn't let you do that.

If you want your index type to be limited private, you'll have to
provide the indexing operations (setting and retrieving elements) as
explicit functions.  If you want to use actual array indexing, you'll
need to use a visibly discrete index type.

-- 
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"



  parent reply	other threads:[~2003-01-12 19:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-11 21:42 Private discrete type as index AG
2003-01-11  2:34 ` James S. Rogers
2003-01-12  0:09   ` AG
2003-01-11  7:16     ` James S. Rogers
2003-01-12  5:47       ` AG
2003-01-11 12:22         ` Dmitry A. Kazakov
2003-01-11 14:36         ` Charles H. Sampson
2003-01-12 19:23 ` Keith Thompson [this message]
2003-01-12 19:48   ` tmoran
2003-01-15 16:45     ` Dmitry A. Kazakov
2003-01-18  6:24       ` AG
2003-01-17 14:14         ` tmoran
2003-01-19  1:38           ` AG
2003-01-18  8:36             ` tmoran
2003-01-19  6:06               ` AG
2003-01-17 16:28         ` 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