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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,63fa88e2f1a3ebea X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail From: zw@cs.man.ac.uk Newsgroups: comp.lang.ada Subject: Re: Universal type in Ada Date: 16 Jun 2005 06:10:44 -0700 Organization: http://groups.google.com Message-ID: <1118927444.744577.187680@f14g2000cwb.googlegroups.com> References: NNTP-Posting-Host: 130.88.192.82 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1118927450 22948 127.0.0.1 (16 Jun 2005 13:10:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 16 Jun 2005 13:10:50 +0000 (UTC) In-Reply-To: User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: f14g2000cwb.googlegroups.com; posting-host=130.88.192.82; posting-account=Z5_cDw0AAAAiVsYHnsUBMTESnujcktdr Xref: g2news1.google.com comp.lang.ada:11415 Date: 2005-06-16T06:10:44-07:00 List-Id: Preben Randhol wrote: > zw wrote on 15/06/2005 (13:11) : > > Hi, I am trying to create a Universal type in Ada such as "Object" in > > Java so that I could define a function that returns a value in this > > Universal type, then I could lower-cast value in this type to its > > specific type such as String, Float or any user-defined types. Because > > in Java if a method returns an Object, it could be casted to any other > > types that are subtypes of Object. Is there a Universal type in Ada? > > Could anyone tell me how to create such types in Ada, please? > > Why would you want to do something like this? Generally you don't want > to use subtypes over types as you loose the advantage of the Ada type > checking... > > Remember that in Ada one can have: > > function Method (Some_Input : Input_Type) return Integer; > function Method (Some_Input : Input_Type) return Float; > function Method (Some_Input : Input_Type) return String; > > And do: > > Number : Integer := Method (Input); > Height : Float := Method (Input); > Text : String := Method (Input); > > then the correct function will be called depending on return type. > > Please explain what you want to do and we can give better hints to do it > in more Ada-wise ways. > > Preben Hi, Thank you very much. We could define a function "Method" that takes same inputs and return different types of results. However, we must know the type of result from a "Method" so that we could declare "Result" as an Integer, Float or String, but the problem is when we don't know the "Result" type, we could not use the function "Method". For example, in Java, .......... Object Method(Input_Type Some_Input){....} .......... Input_Type S1; Object result = Method(S1); .......... where result could an Integer, a Float or an instance of a user-defined Object.