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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9ab1bf4be2d855dd X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-07 15:06:09 PST Path: supernews.google.com!sn-xit-03!supernews.com!nntp.cs.ubc.ca!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newshub2.home.com!news.home.com!news1.sttls1.wa.home.com.POSTED!not-for-mail From: "Mark Lundquist" Newsgroups: comp.lang.ada References: <97pfmt$ll30@tech.port.ac.uk> Subject: Re: Questions: X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Message-ID: Date: Wed, 07 Mar 2001 23:05:28 GMT NNTP-Posting-Host: 24.20.66.55 X-Complaints-To: abuse@home.net X-Trace: news1.sttls1.wa.home.com 984006328 24.20.66.55 (Wed, 07 Mar 2001 15:05:28 PST) NNTP-Posting-Date: Wed, 07 Mar 2001 15:05:28 PST Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: supernews.google.com comp.lang.ada:5526 Date: 2001-03-07T23:05:28+00:00 List-Id: Sorry for the late response (I lost access to news for a while...) WM wrote in message news:97pfmt$ll30@tech.port.ac.uk... > Hi, I am an ada beginner. Can anyone kindly tell me what's the difference > between TYPE and SUBTYPE? This is one of the cool things about Ada, IMHO. It's also very fundamental and one of the keys to "thinking in Ada". It's not well understood by those who learn the language in a "paint-by-numbers" way, but it's really not that complicated, and it's well worth understanding. First of all, what it *doesn't* mean... "subtype" isn't a relationship, it's a kind of entity (so you don't say, "type Foo is a subtype of type Bar"). Nor is a subtype a "kind of type". Also, subtypes have nothing to do with inheritance. The mechanism for inheritance is type *derivation* (in OO literature, the terms "subtype" and "derivation" are both used to denote inheritance; Ada uses the term "derivation" to denote inheritance, and it uses the term "subtype" to mean a very different thing...) Type and subtype are distinctly different entities. But every subtype is associated with some type, which is called "the type of the subtype". Every object has (is "of") a subtype! (and thus also a type). But a *value* does not have a subtype! It has only a type! A type is a set of values, combined with a set of operations. A subtype combines a type with a *constraint*, which describes a subset of the type's values that objects of the subtype are allowed to have. Got that? Type = values + operations. Subtype = type + constraint. A "null constraint" is a constraint that doesn't restrict the set of values. Now then... every type declaration actually declares *two* things: a type and a subtype! This subtype is called the "first subtype" of the type. Technically, types are anonymous in Ada; what is usually thought of as the "type name" is really the name of the first subtype. A subtype declaration declares only a subtype. The type of the new subtype is the same as the type of the subtype named in the declaration, e.g. given subtype S is T; declares a new subtype S of the type of subtype T. This is also an example of a subtype declaration that does not include a constraint, so the constraint of S is the same as the constraint of T. (This is how you "rename" or create an alias for a type). What a subtype declaration looks like that adds a constraint depends on the type of the subtypes, e.g. for an integer type you might have subtype S is T range 1 .. 10; Hope this helps, Mark Lundquist Rational Software