comp.lang.ada
 help / color / mirror / Atom feed
* Upcasting
@ 2002-11-05 11:43 Matthew Baulch
  2002-11-05 12:49 ` Upcasting Lutz Donnerhacke
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Matthew Baulch @ 2002-11-05 11:43 UTC (permalink / raw)


For the records:

...
type Base is tagged with
  record
    Base1, Base2 : Integer;
  end record;

type Derived is new Base with
  record
    Derived1, Derived2 : Float;
  end record;
...
Foo1 : Base;
Foo2 : Derived;
...

Obviously to assign Foo2 to Foo1 you would:
	Foo1 := Base(Foo2);

But if you wanted to assign Foo1 to Foo2:
	Foo2 := (Foo1 with 5.0, 10.0);
would work.

My question is: How would you do this 'upcasting' if varying
types existed? Obviously the compiler could tell where each
value must go based on their type if only one of their type
was needed in the transition. How does this type of thing work?
(or does the A95 compiler not allow it)



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Upcasting
  2002-11-05 11:43 Upcasting Matthew Baulch
@ 2002-11-05 12:49 ` Lutz Donnerhacke
  2002-11-05 17:33 ` Upcasting Stephen Leake
  2002-11-06 15:18 ` Upcasting Georg Bauhaus
  2 siblings, 0 replies; 5+ messages in thread
From: Lutz Donnerhacke @ 2002-11-05 12:49 UTC (permalink / raw)


* Matthew Baulch wrote:
> My question is: How would you do this 'upcasting' if varying
> types existed? Obviously the compiler could tell where each
> value must go based on their type if only one of their type
> was needed in the transition. How does this type of thing work?
> (or does the A95 compiler not allow it)

procedure t is
   type Base is tagged null record;
   type Derivated is new Base with null record;

   d  : Derivated;
   dc : Base'Class := d;
   b  : Base       := Base(d);
   bc : Base'Class := b;
begin
-- d := Base (b);       -- will not compile
   d := Derivated (dc);
   d := Derivated (bc); -- will raised CONSTRAINT_ERROR on run time
end t;



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Upcasting
  2002-11-05 11:43 Upcasting Matthew Baulch
  2002-11-05 12:49 ` Upcasting Lutz Donnerhacke
@ 2002-11-05 17:33 ` Stephen Leake
  2002-11-06  6:26   ` Upcasting Matthew Baulch
  2002-11-06 15:18 ` Upcasting Georg Bauhaus
  2 siblings, 1 reply; 5+ messages in thread
From: Stephen Leake @ 2002-11-05 17:33 UTC (permalink / raw)


"Matthew Baulch" <matt@greenroom.com.au> writes:

> My question is: How would you do this 'upcasting' if varying
> types existed? 

I don't know what you mean by "varying types". You might mean "variant
records", but I doubt it.

Can you give an example of what you mean?

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Upcasting
  2002-11-05 17:33 ` Upcasting Stephen Leake
@ 2002-11-06  6:26   ` Matthew Baulch
  0 siblings, 0 replies; 5+ messages in thread
From: Matthew Baulch @ 2002-11-06  6:26 UTC (permalink / raw)


On Tue, 05 Nov 2002 12:33:51 +0000, Stephen Leake wrote:

> "Matthew Baulch" <matt@greenroom.com.au> writes:
> 
>> My question is: How would you do this 'upcasting' if varying
>> types existed? 
> 
> I don't know what you mean by "varying types". You might mean "variant
> records", but I doubt it.
> 
> Can you give an example of what you mean?

Not variant records. Varying types: eg. several vars with different types:
	Int1, Int2 : Integer;
	Flt1, Flt2 : Float;
	Str1, Str2 : String(1..10);

So, how would you use the: "x := (xxx with xxx, xxx, xxx)" statement
where multiple types are present.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Upcasting
  2002-11-05 11:43 Upcasting Matthew Baulch
  2002-11-05 12:49 ` Upcasting Lutz Donnerhacke
  2002-11-05 17:33 ` Upcasting Stephen Leake
@ 2002-11-06 15:18 ` Georg Bauhaus
  2 siblings, 0 replies; 5+ messages in thread
From: Georg Bauhaus @ 2002-11-06 15:18 UTC (permalink / raw)


Matthew Baulch <matt@greenroom.com.au> wrote:
: But if you wanted to assign Foo1 to Foo2:
:        Foo2 := (Foo1 with 5.0, 10.0);
: would work.

Not sure I understand your question, because it is not obvious to me
what a varying type is. You could do

   foo2 := (foo1 with derived1 =>  5.0, derived2 => 10.0);

: 
: My question is: How would you do this 'upcasting' if varying
: types existed? Obviously the compiler could tell where each
: value must go based on their type if only one of their type
: was needed in the transition.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-11-06 15:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-05 11:43 Upcasting Matthew Baulch
2002-11-05 12:49 ` Upcasting Lutz Donnerhacke
2002-11-05 17:33 ` Upcasting Stephen Leake
2002-11-06  6:26   ` Upcasting Matthew Baulch
2002-11-06 15:18 ` Upcasting Georg Bauhaus

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