[net.lang] ada type semantics query

lmdk (10/28/82)

#R:floyd:-69800:whuxlb:4100001:000:2733
whuxlb!lmdk    Oct 28 14:13:00 1982

Re: What's the difference in the semantics of the following declarations:

	type A is float;
	type A is new float;
	subtype A is float;
	subtype A is new float;

Are they even all legal syntactically?

            ****************************        
   
  The first and fourth declarations are not valid.
  REASONS :
   
    ===>  Type declarations in ADA have the following form
            
             TYPE identifier [discriminant_part] IS type_definition
           
          The first declaration above has a type_name (following the keyword
          IS) and not a type_definition.  For the various allowable formats
          of a type_definition (since there are so many) I recommend that
          you consult the ADA Reference Manual.

          
    ===>  Subtype declarations in ADA have the following form :

             SUBTYPE identifier IS type_name [constraint]

          The fourth declaration has a derived_type_definition (following
          the keyword IS) and not a type_name.  Furthermore,             
          derived_type_definitions (in this case NEW FLOAT) are only used
          in type declarations and not in subtype declarations.
  


  THE difference in semantics between the second and third declarations is
  very subtle.  Both declarations declare a type called A.  This type A in
  both declarations has the same value set and operators as float. However,
  objects declared as of type A based on the second declaration of A  will
  be considered as logically distinct from objects of type float.  This 
  is not true with the third declaration.

  FURTHER CLARIFICATION
 
     Consider the following object declarations :

          Q : float;             -- Q is of type float
          P : A;                 -- P is of type A
     
     If type A was declared using the second declaration then the following
     statement is not valid :

         P := Q;

     This is because P and Q are considered to be of different types.  One
     could get around this by using the type conversion feature of ADA :

         P := A(Q);

     If on the other hand, type A was declared using the third declaration
     then the statement
   
         P := Q;

     is acceptable.

  SUMMARY 

     The second declaration declares a type A that is distinct from the type  
     float but has the same value set and operators as that of float.

     The third declaration declares a type A that is not distinct from 
     the type float and has the same value set and operators as that of float.
     So, in effect the third declaration merely provides another name for
     the type float.
         
                                                Deepak Kohli
					        ...!harpo!whuxlb!lmdk