comp.lang.ada
 help / color / mirror / Atom feed
From: "AG" <ang@xtra.co.nz>
Subject: Re: Private discrete type as index
Date: Sat, 18 Jan 2003 22:06:31 -0800
Date: 2003-01-18T22:06:31-08:00	[thread overview]
Message-ID: <VM8W9.34124$F63.669034@news.xtra.co.nz> (raw)
In-Reply-To: Im8W9.33333$1q3.5319@sccrnsc01


<tmoran@acm.org> wrote in message news:Im8W9.33333$1q3.5319@sccrnsc01...
> > No. What I was originally trying to do was an abstraction as close
> > to the array as possible (booleans do not matter of course - just
> > something to put there). At the same time, I wanted to restrict
> > control of the index to the package implementing it
> > ...
> > So, while I realise I can't (in Ada) provide things like "..",  I can
> > provide +/-/</> operations of varying flavours on the index. This
> > would keep most (not all, but most) of the array semantics in place.
>
>    type x is new integer;
>    type test is array(x range <>) of boolean;
>    function "+"(left, right:x) return x;
>    function "-"(left, right:x) return x;
>    function "*"(left, right:x) return x;
>    etc.

The problem with this approach is that the following
is perfectly legal Ada (after you put it in a package or
so of course):

type x is new integer;
function "+"(left, right:x) return x;
a:x := 1 + 2;

Now, who exactly told the user of the package
that 1 & 2 are valid values for x? The declaration
"new integer" of course. Please note that in one of
my earlier posts in this thread this was exactly the
example I gave - replacing "new integer" with
"limited private". In fact, that's where it's coming
from in the first place...

> would give you quite a lot of control over the index.  Granted you
> don't have "limited" and your user can get around you via type
> conversion

As you could see, no [explicit] type conversions required.

> , but, assuming some discipline by your user, is that
> amount of control still fatally inadequate for your purposes?

Well, I thought that the philosophy of Ada was *not* to assume
any such thing on the part of a user. So, yes, that amount of
control is inadequate.





  reply	other threads:[~2003-01-19  6:06 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
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 [this message]
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