comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: ANN: Simple components v 1.3
Date: Fri, 16 Jan 2004 10:49:57 +0100
Date: 2004-01-16T10:49:57+01:00	[thread overview]
Message-ID: <2ucf009c1gl5rchk3avag0n9uecohff54d@4ax.com> (raw)
In-Reply-To: matsw-E5F2FF.17223315012004@sicinfo.epfl.ch

On Thu, 15 Jan 2004 17:22:33 +0100, Mats Weber <matsw@bluewin.ch>
wrote:

>In article <629d00tlqvu326hi1vsomlmnvkobvbc0bl@4ax.com>,
> Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:
>
>>Isn't it same as to have just set rather than map? I have Generic_Set:
>>
>>generic
>>   type Object_Type is private;
>>   Null_Element : Object_Type;
>>    ...
>>   with function "<" (Left, Right : Object_Type) return Boolean is <>;
>>   with function "=" (Left, Right : Object_Type) return Boolean is <>;
>>package Generic_Set is
>
>I think not, because with maps, you have to be able to extract an item 
>given its key, which you cannot do with Generic_Sets as there is no key 
>type. Following is the function that does that in my package:
>
>   function Search (Key : Key_Type; Within : Bag) return Item_Type;
>      -- Returns the first item in FROM that has a key equal to KEY.
>      -- NONEXISTENT_KEY will be raised if no such item is
>      -- found in the bag.

Mmm, one could use:

function Is_In (Container : Map; Element : Object_Type)
   return Boolean;

Actually here comes the motivation for maps from. I encountered that
it is too expensive in some cases to create a new object to be used in
Is_In. For example, when object is a handle to something large. So I
decided to make maps with keys completely separated from objects. Your
variant is somewhere in between, it is rather set than map. BTW, I
didn't care that String could not be used as a key, because I had
generic tables to deal with that
[http://www.dmitry-kazakov.de/ada/tables.htm] and I saw no other
interesting cases of unconstrained keys. 

-----------------
Some time ago I posted a proposal for proper constructors,
assignments, limited types initialization:

http://groups.google.com/groups?hl=en&lr=lang_en|lang_de|lang_ru&ie=UTF-8&selm=au9fm2%245kta0%241%40ID-77047.news.dfncis.de&rnum=1

That could help to solve the problem of creating unconstrained objects
from unconstrained generic parameters (with some extensions of
discriminants). Something like this:

generic
   type Key_Type (<>) is private;
   ...
package Foo is
   type Token (Constraints : Key_Type'Constraint) is record
      Key : Key_Type (Constraints);
      ...
   end record;

Here Key_Type'Constraint denotes an anonymous null-record type having
exactly same discriminants / bounds as Key_Type. Using this type as a
discriminant for Token one could constrain the Key component.

Interestingly, it seems that this would also allow to copy limited
unconstrained objects without having assignment. But I see no harm in
that.

--
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de



      parent reply	other threads:[~2004-01-16  9:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-03 17:17 ANN: Simple components v 1.3 Dmitry A. Kazakov
2004-01-14 12:06 ` Preben Randhol
2004-01-14 13:15   ` Dmitry A. Kazakov
2004-01-15 14:01     ` Mats Weber
2004-01-15 15:04       ` Dmitry A. Kazakov
2004-01-15 16:22         ` Mats Weber
2004-01-15 18:18           ` Jeffrey Carter
2004-01-16  9:49           ` Dmitry A. Kazakov [this message]
replies disabled

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