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,d8c487e59f13ecdf X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-09 11:37:36 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-06!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: Ada Basics Date: Wed, 9 Oct 2002 14:37:35 -0400 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:29631 Date: 2002-10-09T14:37:35-04:00 List-Id: "prashna" wrote in message news:d40d7104.0210090453.f6aed66@posting.google.com... > Hi all, > What is the difference between declaring a type by using new (ex type > one_to_hundred is new Integer range 1..100) and declaring a type > without using new (type one_to_hundred is range 1..100)? As has been pointed out, the new form indicates derivation, which means the primitive operations of the parent type are inherited by the derived type. For type Integer, it's not obvious what's happening, but consider another type: package P is type T is range 0 .. 200; procedure Inc (O : in out T); end; Here, we have an integer type, that has (in addition to the pre-defined operations for integer types) an increment operation, allowing you to do this: X : T := 0; Increment (X); Now let's create another type that derives from T: with P; package Q is type NT is new P.T; --range is 0 .. 200 end; Type NT inherits the operations of its parent type T, which means NT has an increment operation: Y : NT := 0; Increment (Y); In this example, T is the root of a family of types, and all types in this family have an Inc operation. This is useful if you want to pass any member of this family as a generic formal type: with P; generic type NT is new P.T; package GR is ...; In this example, you can instantiate GR with either P.T or Q.NT: with P; package R is new GR (P.T); with Q; package R is new GR (Q.NT); In the body of GR, you can apply the Inc operation to objects of formal type NT. For scalar types, you're allowed to constrain the range of the parent. In the example above, NT has the same range as its parent (0 .. 200), but we could have made it smaller if that were desired: with P; package Q is type NT is new T range 1 .. 100; --constrain range end; In general, a derivation is allowing you to state that there is a relationship between the types. If no such relationship is necessary, then just declare the type without a derivation: package Q is type T is range 0 .. 200; end;