From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,789d45e53035f912 X-Google-Attributes: gid103376,public From: "Norman H. Cohen" Subject: Re: strong typing Date: 1996/10/10 Message-ID: <325D0247.FEC@watson.ibm.com>#1/1 X-Deja-AN: 188487915 references: <53e6n5$eq2@rc1.vub.ac.be> content-type: text/plain; charset=us-ascii organization: IBM Thomas J. Watson Research Center mime-version: 1.0 reply-to: ncohen@watson.ibm.com newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (Win95; I) Date: 1996-10-10T00:00:00+00:00 List-Id: AGBOH CHARLES wrote: > Ada's strong typing mechanism doest not allow identifiers of different > types to assigned to each other. Why are subtypes and parent type > permitted. Why can derived types and parent types be assigned to each other. > Apparently a derived type and sybtypes are new types so assignment should not > be possible. A subtype is NOT a distinct type, but simply a subset of its type. Given the declaration X: Character := 'N'; the current value of X belongs to type Character, to the subtype Character range 'A' .. 'Z', to the subtype Character range 'G' .. 'R', etc. Indeed, Character itself is a subtype, consisting of every value of the type. A declaration such as subtype ST is Character range 'A' .. 'F'; simply establishes ST as a shorthand for Character range 'A' .. 'F'. (In some places, such as parameter specifications, the syntax of Ada only allows subtype names, so this shorthand is sometimes vital.) In contrast, a derived type IS a new, distinct type, and assignment between a derived type and it parent type is NOT allowed. However, a value of a derived type can be CONVERTED to a value of its parent type, and the converted value can be assigned. (Conversion in the other direction is also possible when the types are not tagged.) Shameless commercial :-) : For a fuller discussion, see Chapter 4 of Ada as a Second Language. The chapter is devoted to these issues. -- Norman H. Cohen mailto:ncohen@watson.ibm.com http://www.research.ibm.com/people/n/ncohen