defines both a type and a subtype

V

valtih1978

Guest
Every type declaration in LRM says that it defines "both a type and a
subtype". What is the idea of that? Why not to define the constrained
type right away?
 
On Tuesday, November 13, 2012 10:56:36 AM UTC-6, valtih1978 wrote:
Every type declaration in LRM says that it defines "both a type and a subtype". What is the idea of that? Why not to define the constrained type right away?
Ok, this has to do with integer, physical and real types, not all types.

The two types allow implicit conversion from mumeric literals, defined only for the anonymous type, to any declared type (really an implicit subtype) of that anonymous type. However, unlike explicit subtypes of the same explicit type, you cannot implicitly convert between implicit subtypes.

type his_real is range 0.0 to 1.0; -- implicit subtype of universal_real
type her_real is range 0.0 to 1.0; -- another implicit subtype of universal_real

variable his : his_real := 0.5; -- both are compatible with anonymous literals
variable hers : her_real := 0.5;

his := hers; -- ERROR! but you can't do this!

However, if you declared his_real and her_real as named subtypes of real, then you could assign from one to the other.


Andy
 
What this has to do with my question? I ask why the declaration cannot
just define a new type. You say that this is done to make the
declarations incompatible on the ground that explicit subtypes are
compatible. But my question is why to do the subtyping in the first
place in the declaration? If I just introduce a single type, without
subtypes, his and her variables can also be defined compatible with the
literal but not with each other.

It is stupid IMO to introduce implicit subtyping. It is even more stupid
to introduce a special rule that matches implicit subtypes differently.
So you defend one stupid rule by introducing another. Is it ok?

Thanks

On 14.11.2012 1:51, Andy wrote:
On Tuesday, November 13, 2012 10:56:36 AM UTC-6, valtih1978 wrote:
Every type declaration in LRM says that it defines "both a type and a subtype". What is the idea of that? Why not to define the constrained type right away?

Ok, this has to do with integer, physical and real types, not all types.

The two types allow implicit conversion from mumeric literals, defined only for the anonymous type, to any declared type (really an implicit subtype) of that anonymous type. However, unlike explicit subtypes of the same explicit type, you cannot implicitly convert between implicit subtypes.

type his_real is range 0.0 to 1.0; -- implicit subtype of universal_real
type her_real is range 0.0 to 1.0; -- another implicit subtype of universal_real

variable his : his_real := 0.5; -- both are compatible with anonymous literals
variable hers : her_real := 0.5;

his := hers; -- ERROR! but you can't do this!

However, if you declared his_real and her_real as named subtypes of real, then you could assign from one to the other.


Andy
 
On 14.11.2012 20:01, Andy wrote:
Oh, I forgot who you were. I refuse to argue with you.

Andy
yes, I like the logic and reason in the argument
 

Welcome to EDABoard.com

Sponsor

Back
Top