From: Natasha Kerensikova <lithiumcat@instinctive.eu>
Subject: Re: How to declare a generic formal type "covered" by another?
Date: Thu, 1 May 2014 07:33:19 +0000 (UTC)
Date: 2014-05-01T07:33:19+00:00 [thread overview]
Message-ID: <slrnlm3u5u.i0l.lithiumcat@nat.rebma.instinctive.eu> (raw)
In-Reply-To: ljsrvg$nbc$1@dont-email.me
Hello,
On 2014-05-01, J-P. Rosen <rosen@adalog.fr> wrote:
> Le 01/05/2014 08:54, Natasha Kerensikova a écrit :
>> So S would have to be a concrete constrained type, but looking at the
>> alternatives for "formal_type_definition", I can't see anything that
>> covers both S being a constrained version of T, and S being a concrete
>> tagged type belonging to class-wide T.
>>
>> Is it possible, or am I hitting a limit of Ada generics?
>
> 1) There is nothing here that requires T to be tagged
Indeed, and I don't want to restrict T to tagged types.
The examples I had in mind are:
- T is Stream_Element_Array, S is Stream_Element_Array (1 .. 4096)
- T is Root_Stream_Type'Class, S is a concrete type derived from it
> 2) You can say that S must be derived from T:
> type S is new T; (non tagged type)
> type S is new T with private; (tagged type)
It looks like I can't cover both cases in a single declaration, can I?
> 3) There is no way to say that S must be constrained, because being
> constrained is a matter of subtype, and only types matter for generics.
Well maybe the problem here is my limited vocabulary. I used the word
"constrained" there only to mean "Something := new S" or "Variable : S;"
are both valid, i.e. objects of that type can be created without
further information. There must be some way to express that in generics.
> The best way to constrain an allocator is by providing an initial value,
> that you could pass as a parameter to Allocate f.e.
That's the solution I have been running with, but yeasterday I hit a
problem with T being Stream_Element_Array and S being
Stream_Element_Array (1 .. 2**29): the intermediate copy and the
allocator result don't fit both in memory, and the program is OOM
killed.
The only solution I found where a limited discriminated record to hold
the Stream_Element_Array, but that's an invasive changed, and somehow
having the allocator run before filling its contents, which means either
exposing the internal access type (so that a client function can call
the allocator and return the access), or providing a generic function
like in the OP (or some other solution I'm unable to come up with).
Thanks for your help,
Natasha
next prev parent reply other threads:[~2014-05-01 7:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-01 6:54 How to declare a generic formal type "covered" by another? Natasha Kerensikova
2014-05-01 7:09 ` J-P. Rosen
2014-05-01 7:33 ` Natasha Kerensikova [this message]
2014-05-01 13:35 ` J-P. Rosen
2014-05-01 17:56 ` Natasha Kerensikova
2014-05-01 20:59 ` Jeffrey Carter
2014-05-02 7:58 ` AdaMagica
2014-05-02 8:17 ` Natasha Kerensikova
2014-05-02 15:12 ` Jeffrey Carter
2014-05-02 15:33 ` Dmitry A. Kazakov
2014-05-02 16:00 ` AdaMagica
2014-05-01 9:30 ` Georg Bauhaus
2014-05-01 9:32 ` Georg Bauhaus
2014-05-01 9:33 ` Georg Bauhaus
2014-05-01 16:34 ` Georg Bauhaus
2014-05-01 18:11 ` Natasha Kerensikova
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox