comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: generic type identification
Date: Sat, 04 Jan 2003 05:39:34 GMT
Date: 2003-01-04T05:39:34+00:00	[thread overview]
Message-ID: <qsuR9.551617$WL3.150846@rwcrnsc54> (raw)
In-Reply-To: H5rR9.3971$FF4.246557@newsb.telia.net

> generic
>   type New_Type is range <>;
> Is it possible to identify the type of New_Type in the Some_Procedure
> procedure?
Suppose:
    type Snowmans_Pleasant_Farenheit is range 18 .. 24;
    type My_Pleasant_Centigrade is range 18 .. 24;
    package My_Procedure is new Example.Some_Procedure(My_Pleasant_Centigrade);
  How could your Some_Procedure tell whether it was instantiated with
Farenheit or Centigrade temperatures, especially since the code that
instantiates it, and the two temperature "types", may not have even existed
when you wrote your package Example?

> Another thing that I couldn't find an answer to, is it possible to constrain
> the allowed generic types. Like specifying that New_Type has to be either
> Integer or Float?
> generic
>   type New_Type is range <>;
    type Other_Type is digits <>;
  New_Type is a signed integer of some sort.  (Perhaps My_Pleasant_Centigrade)
  Other_Type is some kind of floating point type.  And there are other
notations for modular, fixed, private, discrete, etc.

> The alternative, I guess, would be to not use a generic package and instead
> overload Some_Procedure with those types that I want to be able to use but
> this will clutter the specification file =(.
    Not to mention that you will have to add to package Example every time
someone wants to use your Some_Procedure with a new type.
  Why do you want Some_Procedure to know what type it was instantiated
with?  How much does it need to know about that type - just whether it's
integer or float or modular, or does it need to know whether it's
My_Pleasant_Centigrade or not?



  parent reply	other threads:[~2003-01-04  5:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-04  1:50 generic type identification David Holm
2003-01-04  2:04 ` chris.danx
2003-01-04  5:39 ` tmoran [this message]
2003-01-04 12:39   ` David Holm
2003-01-04 16:13     ` James S. Rogers
2003-01-05  3:28       ` David Holm
2003-01-05 10:03         ` Gautier
2003-01-04 19:27     ` tmoran
2003-01-05  3:25       ` David Holm
2003-01-05  5:42         ` tmoran
2003-01-06 17:56     ` Stephen Leake
replies disabled

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