* recursive types and generics
@ 2003-05-02 16:19 alfonso acosta
2003-05-02 17:09 ` Robert A Duff
2003-05-02 17:12 ` Ludovic Brenta
0 siblings, 2 replies; 3+ messages in thread
From: alfonso acosta @ 2003-05-02 16:19 UTC (permalink / raw)
Hi:
I need to code a recursive type: a Sequence which could contain
sequences of the same type. Im trying to use a generic package for that
purpouse. I provide a simplified example:
-------------------------------------------------------------------------
type Elem_Type is (Nothing, Int, Seq);
type Seq_Acces;
type Seq_Elem (Const : Elem_Type := Nothing) is
record
case Const is
when Nothing => null;
when Int => I : Integer;
when Seq => S : Seq_Access;
-- "invalid use of type before its full declaration"
end case;
end record;
package Myseq is new Sequence (Element => Seq_Elem);
type Seq_Access is access Myseq.Sequence; -- provided by the generic
-- package
--------------------------------------------------------------------------
Any ideas about fixing it?
Alfonso Acosta
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: recursive types and generics
2003-05-02 16:19 recursive types and generics alfonso acosta
@ 2003-05-02 17:09 ` Robert A Duff
2003-05-02 17:12 ` Ludovic Brenta
1 sibling, 0 replies; 3+ messages in thread
From: Robert A Duff @ 2003-05-02 17:09 UTC (permalink / raw)
alfonso acosta <alfonso_acosta_mail@yahoo.es> writes:
> Hi:
>
> I need to code a recursive type: a Sequence which could contain
> sequences of the same type. Im trying to use a generic package for that
> purpouse. I provide a simplified example:
>
> -------------------------------------------------------------------------
> type Elem_Type is (Nothing, Int, Seq);
>
> type Seq_Acces;
>
> type Seq_Elem (Const : Elem_Type := Nothing) is
> record
> case Const is
> when Nothing => null;
> when Int => I : Integer;
> when Seq => S : Seq_Access;
> -- "invalid use of type before its full declaration"
> end case;
> end record;
>
> package Myseq is new Sequence (Element => Seq_Elem);
>
> type Seq_Access is access Myseq.Sequence; -- provided by the generic
> -- package
> --------------------------------------------------------------------------
>
> Any ideas about fixing it?
>
> Alfonso Acosta
How about something like this?
type Seq_Elem is tagged limited null record;
package Myseq is new Sequence (Element => Seq_Elem'Class);
type Seq_Access is access Myseq.Sequence;
type Int_Seq_Elem is new Seq_Elem with
record
I: Integer;
end record;
type Seq_Seq_Elem is new Seq_Elem with
record
S: Seq_Access;
end record;
- Bob
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: recursive types and generics
2003-05-02 16:19 recursive types and generics alfonso acosta
2003-05-02 17:09 ` Robert A Duff
@ 2003-05-02 17:12 ` Ludovic Brenta
1 sibling, 0 replies; 3+ messages in thread
From: Ludovic Brenta @ 2003-05-02 17:12 UTC (permalink / raw)
How about this:
procedure Test is
generic
type Element is private;
package Sequence is
type Kind_Of_Element is (Nothing, Leaf, Seq);
type Sequence_Element (Kind : Kind_Of_Element) is private;
type Sequence is access Sequence_Element;
private
type Sequence_Element (Kind : Kind_Of_Element) is record
Next_Element : Sequence;
case Kind is
when Nothing => null;
when Leaf => Payload : Element;
when Seq => Sub_Sequence : Sequence;
end case;
end record;
end Sequence;
package My_Sequence is new Sequence (Element => Integer);
type Seq_Access is new My_Sequence.Sequence;
begin
null;
end Test;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-05-02 17:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-02 16:19 recursive types and generics alfonso acosta
2003-05-02 17:09 ` Robert A Duff
2003-05-02 17:12 ` Ludovic Brenta
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox