comp.lang.ada
 help / color / mirror / Atom feed
* declaration of an incomplete private type before the private part
@ 2008-02-01  8:28 Javi
  2008-02-01  8:49 ` Niklas Holsti
  2008-02-01 14:00 ` Robert A Duff
  0 siblings, 2 replies; 4+ messages in thread
From: Javi @ 2008-02-01  8:28 UTC (permalink / raw)


hi guys,

I'm very newbye to ADA, so my apologizes in advance.

My problem: I need to do a declaration such as:

-----------------------------------------
...
   type ListNode is private;
   type List is private;

   package IterList is new Iterators   (Creator => List,
                                        Item => ListNode,
                                        getFirst => Lists.getFirst,
                                        getNext => Lists.getNext,
                                        isLast => Lists.isLast);

   function makeIter (L : List) return IterList.Iterator;
...
   private:
      (complete declaration of ListNode and List)
-----------------------------------------


The problem is that I need to complete the type (ListNode and List)
before instancing the new package. But I do not know how to do that!
The only solution I have found is to declare the types non-private and
then give them the complete declaration. Obviously, this solution does
not satisfy me since I want to make the types private.

Can anyone help me, please?

Thanks in advance,
Javier



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

* Re: declaration of an incomplete private type before the private part
  2008-02-01  8:28 declaration of an incomplete private type before the private part Javi
@ 2008-02-01  8:49 ` Niklas Holsti
  2008-02-01  9:53   ` Javi
  2008-02-01 14:00 ` Robert A Duff
  1 sibling, 1 reply; 4+ messages in thread
From: Niklas Holsti @ 2008-02-01  8:49 UTC (permalink / raw)


Javi wrote:

> My problem: I need to do a declaration such as:
> 
> -----------------------------------------
> ...
>    type ListNode is private;
>    type List is private;
> 
>    package IterList is new Iterators   (Creator => List,
>                                         Item => ListNode,
>                                         getFirst => Lists.getFirst,
>                                         getNext => Lists.getNext,
>                                         isLast => Lists.isLast);
> 
>    function makeIter (L : List) return IterList.Iterator;
> ...
>    private:
>       (complete declaration of ListNode and List)
> -----------------------------------------
> 
> 
> The problem is that I need to complete the type (ListNode and List)
> before instancing the new package. But I do not know how to do that!
> The only solution I have found is to declare the types non-private and
> then give them the complete declaration. Obviously, this solution does
> not satisfy me since I want to make the types private.

As I understand it, you want to instantiate the Iterators package 
before the "private" part, because you want to use the type 
Iterator, defined in the instance, in the declaration of public 
oeprations (makeIter). One way to work around this problem is to 
define a new type for that purpose:

    type ListNode     is private;
    type List         is private;
    type ListIterator is private;   -- Added.

    function makeIter (L : List) return ListIterator;

    private

    type ListNode is ... -- Complete declaration.
    type List is     ... -- Complete declaration.

    packate IterList is new Iterators (....);  -- As above.

    type ListIterator is new IterList.Iterator;

HTH,

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



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

* Re: declaration of an incomplete private type before the private part
  2008-02-01  8:49 ` Niklas Holsti
@ 2008-02-01  9:53   ` Javi
  0 siblings, 0 replies; 4+ messages in thread
From: Javi @ 2008-02-01  9:53 UTC (permalink / raw)


On 1 feb, 09:49, Niklas Holsti <niklas.hol...@tidorum.invalid> wrote:
> Javi wrote:
> > My problem: I need to do a declaration such as:
>
> > -----------------------------------------
> > ...
> >    type ListNode is private;
> >    type List is private;
>
> >    package IterList is new Iterators   (Creator => List,
> >                                         Item => ListNode,
> >                                         getFirst => Lists.getFirst,
> >                                         getNext => Lists.getNext,
> >                                         isLast => Lists.isLast);
>
> >    function makeIter (L : List) return IterList.Iterator;
> > ...
> >    private:
> >       (complete declaration of ListNode and List)
> > -----------------------------------------
>
> > The problem is that I need to complete the type (ListNode and List)
> > before instancing the new package. But I do not know how to do that!
> > The only solution I have found is to declare the types non-private and
> > then give them the complete declaration. Obviously, this solution does
> > not satisfy me since I want to make the types private.
>
> As I understand it, you want to instantiate the Iterators package
> before the "private" part, because you want to use the type
> Iterator, defined in the instance, in the declaration of public
> oeprations (makeIter). One way to work around this problem is to
> define a new type for that purpose:
>
>     type ListNode     is private;
>     type List         is private;
>     type ListIterator is private;   -- Added.
>
>     function makeIter (L : List) return ListIterator;
>
>     private
>
>     type ListNode is ... -- Complete declaration.
>     type List is     ... -- Complete declaration.
>
>     packate IterList is new Iterators (....);  -- As above.
>
>     type ListIterator is new IterList.Iterator;
>
> HTH,
>
> --
> Niklas Holsti
> Tidorum Ltd
> niklas holsti tidorum fi
>        .      @       .

many thanks :-)



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

* Re: declaration of an incomplete private type before the private part
  2008-02-01  8:28 declaration of an incomplete private type before the private part Javi
  2008-02-01  8:49 ` Niklas Holsti
@ 2008-02-01 14:00 ` Robert A Duff
  1 sibling, 0 replies; 4+ messages in thread
From: Robert A Duff @ 2008-02-01 14:00 UTC (permalink / raw)


Javi <fjvera@gmail.com> writes:

> hi guys,
>
> I'm very newbye to ADA, so my apologizes in advance.
>
> My problem: I need to do a declaration such as:
>
> -----------------------------------------
> ...
>    type ListNode is private;
>    type List is private;
>
>    package IterList is new Iterators   (Creator => List,
>                                         Item => ListNode,
>                                         getFirst => Lists.getFirst,
>                                         getNext => Lists.getNext,
>                                         isLast => Lists.isLast);
>
>    function makeIter (L : List) return IterList.Iterator;
> ...
>    private:
>       (complete declaration of ListNode and List)
> -----------------------------------------
>
>
> The problem is that I need to complete the type (ListNode and List)
> before instancing the new package. But I do not know how to do that!
> The only solution I have found is to declare the types non-private and
> then give them the complete declaration. Obviously, this solution does
> not satisfy me since I want to make the types private.

This is a flaw in the design of Ada.  You can't instantiate a generic
with a private type, in the same package where the private type is
declared, and make the instantiation visible to clients (i.e. put it
in the visible part).

Your solution above (don't make it private) works.
Niklas Holsti gave another solution.

A third solution is to put the instantiation in a child
package, or make it a child itself.  Then clients have
to "with" both the parent and the child.  This won't work
if the private part needs to see the instantiation,
but it's OK if the body needs to see the instantiation.

- Bob



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

end of thread, other threads:[~2008-02-01 14:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-01  8:28 declaration of an incomplete private type before the private part Javi
2008-02-01  8:49 ` Niklas Holsti
2008-02-01  9:53   ` Javi
2008-02-01 14:00 ` Robert A Duff

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