From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a883dc07df0d6bb1 X-Google-Attributes: gid103376,public From: Tucker Taft Subject: Re: Numeric types Date: 1999/12/08 Message-ID: <384EC260.E62F662@averstar.com>#1/1 X-Deja-AN: 558281328 Content-Transfer-Encoding: 7bit Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.burl.averstar.com References: <8233fm$ngf$1@nntp3.atl.mindspring.net> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: AverStar (formerly Intermetrics) Burlington, MA USA Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-12-08T00:00:00+00:00 List-Id: 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