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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3eec69188f5bf88a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Extended Type Statements Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Tue, 17 Jan 2006 20:57:30 +0100 Message-ID: NNTP-Posting-Date: 17 Jan 2006 20:57:25 MET NNTP-Posting-Host: e14eafb6.newsread4.arcor-online.net X-Trace: DXC=\>jn]\fnkCLbSWda:jMWf@:ejgIfPPldDjW\KbG]kaMHA@_25la3nbB@OSh4R9@6kB[6LHn;2LCVN[ On Tue, 17 Jan 2006 18:04:03 GMT, Jeffrey R. Carter wrote: > A type defines a set of values and a set of operations on those values. That's > the definition I learned, and is similar to the one in ARM 3.2. In Ada, some > type declaration statements define at type, while others don't. For example > > type I is range 1 .. 10; > > declares a set of values (1 .. 10) and a set of operations on those values ("+", > "-", and so on), while > > type T is limited private; > > declares no values and very few operations. Instead, it's the entire package > spec that T is in that defines the type: > > package P_For_T is > type T is limited private; > > C : constant T; > > procedure Put (Into : in out T; Value : in Integer); > > function Get (From : T) return Integer; > private -- P_For_T > ... > end P_For_T; > > I was wondering if it might be a good idea for a language (probably not Ada) to > have an extended type statement that covers both concepts with a single > statement. So an integer type could be declared as something like > > type I is > values => > range 1 .. 10; > end I; > > and an ADT as > > type T is > values => > C : constant; > operations => > limited => True; > > procedure Put (Into : in out T; Value : in Integer); > > function Get (From : T) return Integer; > implementation => > private; > end T; > > There could be sections in the statement for representation clauses and the like. > > Any comments? Would this sort of thing have any value? Some unsorted comments. In ADT approach literals are undistinguishable constructing functions. So there is no need to have any special constructs to denote them. Further, types algebra (what actually Ada needs in a more elaborated from than just record/array aggregation and tagged extension) offers many opportunities. For example infinite literals like Universal_Integer and Strings, can be easily incorporated through interface inheritance. You just say that the type I implements a numeric interface and compiler will routinely convert each Universal_Integer to your type by calling a conversion function you define. This is close to your idea of T with Put and Get. Just consider them as conversion functions *required* by the compiler because T is declared as implementing the interface of Universal_Integer. Same with aggregates as constructing functions, there is no chance to enumerate all possible array aggregates in a "type"-statement. What for? Just let the user to define an aggregate-constructor. Done. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de