comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: limited /non-limited tagged type
Date: Fri, 4 Mar 2011 15:34:04 -0800 (PST)
Date: 2011-03-04T15:34:04-08:00	[thread overview]
Message-ID: <be4948a1-3e99-477b-a5a4-abea49097878@r19g2000prm.googlegroups.com> (raw)
In-Reply-To: 40bfb845-7868-4536-886b-496e8dc82cb4@hd10g2000vbb.googlegroups.com

On Mar 4, 10:56 am, Hacid <chadi.alku...@gmail.com> wrote:
> Hi,
>
> I haven't found an existing topic about this, so I ask my question :
>
> I develop a package for colleagues. In this package I define a tagged
> type. I want to prevent them from doing assignments on this type. But
> I want to be able to do these assignments in my body.
>
> I understand why I can't define my type limited in the public part and
> not limited in the private part. But is there a way to do what I
> want ?
>
> Something like :
>
> package Foo is
>
>    type Object is tagged private;
>
>    function ":=" (Left : out Object,; Right : in Object) is abstract;
> -- I know this looks strange
>
> end Foo;
>
> Thanks.

I think we might need a little more information ...

First of all, why does Object have to be visibly tagged?  That is, why
do users of the package Foo need to see Object as tagged?  I presume
that this is because you want those users to be able to declare type
extensions of Object.  (If not, you can just declare Object as
"limited private" and make the full view tagged and non-limited.)

OK, so you want a user to be able to declare their own type extension:

   type Another_Object is new Foo.Object with record ... end record;

The next question is, why do you need to assign Objects in the body of
Foo?  If this is to implement some operation in Foo:

   package Foo is
      type Object is tagged private;
      procedure Operation (X : in out Object...);

or something like that, then perhaps you want Operation to be able to
do an assignment operation.  Here's the problem: When the user
declares Another_Object, won't they probably need to declare an
overriding version of Operation?  And if part of Operation's purpose
involves assignment, then wouldn't the overriding version of Operation
also need to do assignment, in order to carry out its purpose?  But
you've said that you want to prevent assignment.

Basically, I'm having trouble seeing how this could be the real
problem.  That is, even if you could declare a non-limited tagged type
and remove the ":=" operation, in all probability I think you're going
to realize that there are other problems with your design.  I could be
wrong.  If you can explain what you're trying to accomplish, that
might help point us to a solution.

                              -- Adam



  parent reply	other threads:[~2011-03-04 23:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-04 18:56 limited /non-limited tagged type Hacid
2011-03-04 19:54 ` Edward Fish
2011-03-04 21:18   ` Hacid
2011-03-05  0:17     ` Edward Fish
2011-03-04 20:10 ` Georg Bauhaus
2011-03-04 21:55   ` Hacid
2011-03-04 22:21     ` Hacid
2011-03-05  1:20       ` Randy Brukardt
2011-03-04 22:22     ` Georg Bauhaus
2011-03-04 22:40       ` Hacid
2011-03-05  1:29         ` Georg Bauhaus
2011-03-04 23:34 ` Adam Beneschan [this message]
2011-03-05  3:26 ` Adam Beneschan
2011-03-05 16:48   ` Hacid
replies disabled

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