comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Building limited types through nested creator functions
Date: Mon, 6 Feb 2012 16:53:47 -0800 (PST)
Date: 2012-02-06T16:53:47-08:00	[thread overview]
Message-ID: <57a267ec-b901-401e-b415-ca6d9cf47616@d15g2000yqg.googlegroups.com> (raw)
In-Reply-To: f7678d6e-6746-485f-a148-4f0821ffe9ed@e27g2000vbu.googlegroups.com

On Feb 6, 4:27 pm, Simon Belmont <sbelmont...@gmail.com> wrote:
> On Feb 6, 7:03 pm, Adam Beneschan <a...@irvine.com> wrote:
>
> > (2) If you want users of the package to create an Inner, and then
> > create an Outer that *refers* to that same Inner (without making a
> > copy), then you shouldn't object to using access types (in the private
> > part).
>
> It is basically this, and I really have no objection in using the
> access type.  But since Ada can do it for a public type, I was just
> interested if there was some sort of official way for a private type
> (which would avoid the necessary evils of lifetime control,
> accessibility, etc.)

For a public type, the program has the information that an Outer
contains an Inner (assuming you don't use access types).  Thus it can
create the Outer and its Inner at the same time, using a single
aggregate.  You can't create an Inner first and then create an Outer
later, even if it's a public type.

Since this information is private, the body of your package is the
only one that knows that an Outer contains an Inner; therefore, it's
the body of your package that has to create an Outer and an Inner at
the same time.  Based on that, I don't think your objection to
Shark8's solution makes sense.

I'm assuming here that you really want an Outer to *contain* an Inner,
rather than an Outer containing a *reference* to an Inner.  And I mean
this in terms of an abstract description of your problem, not in terms
of using an access type as your mechanism for implementing all this.
But since you're now saying that an Outer actually *refers* to an
Inner, in your problem description, I guess the whole discussion may
be moot.  You really are going to have to decide what you want.  Is an
Inner a separate kind of object that you want package users to be able
to have independently of an Outer?  Does it make sense for the program
to declare a standalone object of type Inner and use it?  Or does an
Inner make sense only as part of the larger Outer object?

                             -- Adam





  reply	other threads:[~2012-02-07  0:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-05 22:03 Building limited types through nested creator functions Simon Belmont
2012-02-06 12:44 ` Julian Leyh
2012-02-06 19:11 ` Shark8
2012-02-06 22:33   ` Simon Belmont
2012-02-07  0:03 ` Adam Beneschan
2012-02-07  0:27   ` Simon Belmont
2012-02-07  0:53     ` Adam Beneschan [this message]
2012-02-07  2:19       ` Simon Belmont
2012-02-07  9:10         ` Dmitry A. Kazakov
2012-02-07 10:58           ` Georg Bauhaus
2012-02-07 13:25             ` Dmitry A. Kazakov
2012-02-07 14:43               ` Yannick Duchêne (Hibou57)
2012-02-07 15:08                 ` Dmitry A. Kazakov
2012-02-07 17:04 ` Robert A Duff
replies disabled

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