comp.lang.ada
 help / color / mirror / Atom feed
From: zw@cs.man.ac.uk
Subject: Re: Universal type in Ada
Date: 16 Jun 2005 06:10:44 -0700
Date: 2005-06-16T06:10:44-07:00	[thread overview]
Message-ID: <1118927444.744577.187680@f14g2000cwb.googlegroups.com> (raw)
In-Reply-To: <mailman.38.1118846083.17633.comp.lang.ada@ada-france.org>



Preben Randhol wrote:
> zw <zw@cs.man.ac.uk> 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.




  reply	other threads:[~2005-06-16 13:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-15 13:07 Universal type in Ada zw
2005-06-15 13:32 ` Larry Kilgallen
2005-06-16 13:13   ` zw
2005-06-16 14:36     ` Preben Randhol
2005-06-17  2:54     ` Stephen Leake
2005-06-19 17:38     ` Martin Krischik
2005-06-15 13:55 ` Dmitry A. Kazakov
2005-06-15 14:37   ` Preben Randhol
2005-06-15 16:48     ` Dmitry A. Kazakov
2005-06-15 14:34 ` Preben Randhol
2005-06-16 13:10   ` zw [this message]
2005-06-15 16:31 ` Georg Bauhaus
2005-06-16  8:18 ` Ole-Hjalmar Kristensen
2005-06-16 11:59   ` Dmitry A. Kazakov
2005-06-16 13:23     ` zw
2005-06-16 14:19       ` jimmaureenrogers
2005-06-16 14:31       ` Dmitry A. Kazakov
2005-06-19 17:31       ` Martin Krischik
2005-06-19 17:26 ` Martin Krischik
replies disabled

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