Re: type and subtype



On Sun, 24 Jul 2005 16:40:26 GMT, Jeffrey Carter wrote:

> Ludovic Brenta wrote:
>>
>> Two subtypes of the same type are compatible with one another. One
>> can convert between them using an implicit type conversion (i.e. no
>> special syntax required).
>
> There is no type conversion between subtypes of the same type, since
> they are the same type. There are checks that the value of the source
> matches the constraints of the destination.

This sounds much like hairsplitting. However it is an important issue for
the future.

I think that Ludovic's view is more consistent: checks are just a part of
the conversion which otherwise is an identity function, because *presently*
the representation is required to be same. But representation is an
implementation detail and thus cannot count. Moreover it is very desirable
to allow subtypes having different representations. For example: statically
constrained subtypes with removed constant discriminants from their values;
T'Class constrained to some specific type S could remove the type tag from
its objects, etc. Such subtypes would require more-than-checks conversions.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.



Relevant Pages

  • Re: On pragma Precondition etc.
    ... there is pragma Assert for that. ... it is not a contract. ... Ada constraints are not contracts. ... we would consider constraints in the sense of Ada subtypes. ...
    (comp.lang.ada)
  • Re: How to put 200 into an integer sub-type of 16 bits (code included)
    ... right to put their own restrictions on representation items. ... Nothing about specifying it for non-first subtypes. ... but the second sentence of ...
    (comp.lang.ada)
  • Re: Operation can be dispatching in only one type
    ... Why not to allow such constraints for subtypes? ... a precondition can depend on multiple parameters at ... Subtypes should complement them for dynamic run-time checks (recoverable ...
    (comp.lang.ada)
  • Re: How to put 200 into an integer sub-type of 16 bits (code included)
    ... specific aspects may differ for different subtypes of the same type". ... that says that "Size and Alignment clauses" are subtype-specific ... paragraph are about representation items, ...
    (comp.lang.ada)
  • Re: Array slices and types
    ... S'Base and S are subtypes of the same *type*. ... No need to excuse, you are right, I don't see any semantic difference ... may be different subtypes (have different constraints), ... the array subtype S. It would still fit into ...
    (comp.lang.ada)