comp.lang.ada
 help / color / mirror / Atom feed
From: Tucker Taft <stt@averstar.com>
Subject: Re: Numeric types
Date: 1999/12/08
Date: 1999-12-08T00:00:00+00:00	[thread overview]
Message-ID: <384EC260.E62F662@averstar.com> (raw)
In-Reply-To: Pine.LNX.4.10.9912081930170.2845-100000@lexis.di.fct.unl.pt

Mario Amado Alves wrote:
> 
> The manual defines "numeric types" as the set of integer and real types
> (cf. e.g. 3.5).
> 
> Now, is it a codeable type, viz. is it possible to have a generic formal
> parameter of numeric type, meaning inheriting all numeric operations ("+",
> "*", ...)? E.g.:
> 
>   generic
>     type Numeric_Type is ...; -- what here?

generic
  type Numeric_Type is private;
  with function "+"(Left, Right : Numeric_Type) return Numeric_Type is <>;
  with function "*"(...
  ...
  Zero : in Numeric_Type;
package blob is ...
 
> Is this possible to code properly? And how would we write "zero" in this
> idiom (or any other literal for that matter)? It must be a commonality of
> "0" and "0.0". This would perhaps work:
> 
>   function Zero return Numeric_Type is
>   begin
>     return(Numeric_Type'Value("0"));
>   exception
>     when others =>
>       return(Numeric_Type'Value("0.0"));
>   end Zero;
> 
> but it sounds like a dirty trick. An attribute 'Zero would be nice...

Just make zero a generic formal parameter.
You could also create a generic "signature" for a numeric type,
and then take any instantiation of that signature.  E.g.:

   generic
       type Num is private;
       with function "+"(...   -- as above
       Zero : in Num;
       One : in Num;
       with function Image(N : Num) return String;
       with function Value(S : String) return Num;
   package Numeric_Signature is end;

   generic
       with package Num_Pkg is new Numeric_Signature(<>);
   package Blob is
       use Num_Pkg;
       ...

   package Integer_Num is new Numeric_Signature(Integer, Zero => 0, One => 1,
     Integer'Image, Integer'Value);

   package Integer_Blob is new Blob(Num_Pkg => Integer_Num);

> But I am afraid the idiom is just not possible. Please confirm. Perhaps
> with class wide programming... 

Generics are pretty powerful.  The concept of a generic
signature can help reduce the number of parameters
passed to each generic.

> ...
> Thanks in advance for any suggestions.
> 
> | |,| | | |RuaFranciscoTaborda24RcD 2815-249CharnecaCaparica 351+212976751
> |M|A|R|I|O|                                                  mob 939354005
> |A|M|A|D|O|DepartmentoDeInformaticaFCT/UNL 2825-114 Caparica 351+212958536
> |A|L|V|E|S|                                                  fax 212948541
> | | | | | |                 maa@di.fct.unl.pt                FCT 212948300
-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




  reply	other threads:[~1999-12-08  0:00 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-28  0:00 Decoding an octet stream Florian Weimer
1999-11-29  0:00 ` David C. Hoos, Sr.
1999-11-30  0:00   ` Florian Weimer
1999-12-03  0:00     ` Robert Dewar
1999-12-01  0:00   ` Robert Dewar
1999-12-01  0:00     ` Geoff Bull
1999-12-01  0:00       ` Robert Dewar
1999-12-01  0:00     ` David C. Hoos, Sr.
1999-12-01  0:00       ` Robert Dewar
1999-12-07  0:00         ` Stefan Skoglund
1999-12-01  0:00       ` swhalen
1999-12-01  0:00         ` Larry Kilgallen
1999-12-01  0:00           ` Kenneth Almquist
1999-12-02  0:00             ` Geoff Bull
1999-12-02  0:00               ` Stupid patent tricks (was: Decoding an octet stream) Ted Dennison
1999-12-06  0:00               ` Decoding an octet stream Kenneth Almquist
1999-12-01  0:00         ` Florian Weimer
1999-12-02  0:00           ` Geoff Bull
1999-12-02  0:00             ` Lutz Donnerhacke
1999-12-02  0:00           ` Robert Dewar
1999-12-02  0:00           ` Ted Dennison
1999-12-02  0:00             ` tmoran
1999-12-02  0:00         ` Geoff Bull
1999-12-02  0:00           ` swhalen
1999-12-02  0:00             ` Larry Kilgallen
1999-12-03  0:00               ` swhalen
1999-12-04  0:00                 ` Robert Dewar
1999-12-04  0:00                 ` Geoff Bull
1999-12-06  0:00                   ` Robert Dewar
1999-12-03  0:00               ` Geoff Bull
1999-12-06  0:00               ` Richard D Riehle
1999-12-06  0:00                 ` Ed Falis
1999-12-07  0:00                   ` Ted Dennison
1999-12-08  0:00                 ` Robert Dewar
1999-12-08  0:00                   ` Brian Rogoff
1999-12-02  0:00           ` Robert Dewar
1999-12-08  0:00         ` Numeric types Mario Amado Alves
1999-12-08  0:00           ` Tucker Taft [this message]
1999-12-01  0:00       ` Decoding an octet stream Robert Dewar
replies disabled

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