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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.am4!peer.am4.highwinds-media.com!peer04.fr7!futter-mich.highwinds-media.com!news.highwinds-media.com!fx29.am4.POSTED!not-for-mail From: Felix Krause Newsgroups: comp.lang.ada Message-ID: <2017072721383428219-contact@flyx.org> References: <2017072417413775878-contact@flyx.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: Smart Pointers and Tagged Type Hierarchies User-Agent: Unison/2.2 X-Complaints-To: abuse@eweka.nl NNTP-Posting-Date: Thu, 27 Jul 2017 19:38:33 UTC Organization: Eweka Internet Services Date: Thu, 27 Jul 2017 21:38:34 +0200 X-Received-Bytes: 2260 X-Received-Body-CRC: 4275396634 X-Original-Bytes: 2209 Xref: news.eternal-september.org comp.lang.ada:47523 Date: 2017-07-27T21:38:34+02:00 List-Id: On 2017-07-24 21:24:58 +0000, Chris Moore said: >> * A derived type, if it wants to provide additional operations (like >> Current_Position), must not only derive from Instance, but also from >> Reference, to be able to provide an type-safe interface to those >> operations. > > Why? All ops on Instance-derived types (including constructing > subprograms) should be in terms of that type. References are for > access only (ho ho). Well, if the smart pointer for File_Stream is the same type as the smart pointer for Stream, I'd need to downcast the retrieved access type each time I want to call a subroutine only defined for File_Stream, such as Current_Position in my example. An explicit downcast is undesirable because it implies that it may fail, which it cannot when I create a File_Stream reference with a construction subroutine and subsequently call Current_Position on it. > I had to do this kind of thing a great deal in the Ada version of the > mal lisp interpreter. See for example: > > https://github.com/zmower/mal/blob/master/ada/smart_pointers.ads > https://github.com/zmower/mal/blob/master/ada/types.ads > > But my advice is to avoid tagged types if you can. They only make > sense if your problem is wildly dynamic or you want to be lazy when > thinking about memory allocation. mal qualified on both counts. The sad thing is that I really like the prefix notation, which drags me towards tagged types, even though I don't like dispatching that much. Also, controlled types are tagged types, so it is hard to avoid them. -- Regards, Felix Krause