From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=0.3 required=3.0 tests=BAYES_00,NICE_REPLY_A, PDS_OTHER_BAD_TLD,REPLYTO_WITHOUT_TO_CC,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: Re: project euler 26 Date: Sat, 9 Sep 2023 10:13:44 +0200 Organization: A noiseless patient Spider Message-ID: References: <878r9mudvj.fsf@bsb.me.uk> <87a5u1u1yv.fsf@bsb.me.uk> <8734ztttpc.fsf@bsb.me.uk> <87fs3ssl6v.fsf@bsb.me.uk> <87a5u0rts0.fsf@bsb.me.uk> <87jzt3qqlb.fsf@bsb.me.uk> <87o7ieq3ne.fsf@bsb.me.uk> <87tts4ml8z.fsf@bsb.me.uk> Reply-To: nonlegitur@notmyhomepage.de MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 9 Sep 2023 08:13:44 -0000 (UTC) Injection-Info: dont-email.me; posting-host="b705c2fa5397d0af27159c4b5381eee1"; logging-data="4192066"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19C9y5qXLHsa/KpjbDg2DENArYtJfgkxKA=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Cancel-Lock: sha1:wC3vBWgAcl5t8gCwfZlyAciDjew= In-Reply-To: <87tts4ml8z.fsf@bsb.me.uk> Content-Language: en-US Xref: news.eternal-september.org comp.lang.ada:65623 List-Id: On 08.09.23 23:02, Ben Bacarisse wrote: > "G.B." writes: > >> On 07.09.23 01:32, Ben Bacarisse wrote: >> >> >>> A fix (though it's not really ideal) would be to use function >>> composition here (inventing . as the composition operator): >> >> Hm. A stateful, composed function that needs to be applied >> in a certain way. Is that so different from calling interface >> subprograms of a certain type? > > There was nothing stateful (as I understand the term) in either function > being composed. The "apparatus" that the computation needs in order to remember "max so far" looks like part of its state to me. Somehow "the function" needs to operate this state and evaluate it. Extend this to: - find the maximum of [the maxima of] these n collections - find the maximum in this stream at 10 seconds from now. Is it possible, or practical, to define a pure function so that calling it will remember the needed information, n >= 0 being arbitrary? >> So, does type composition help? > > My turn to guess now: you are not being serious? I see no connection to > monads or type composition. In the following sense: There is an object of type So_Far that can remember objects of any type T, them coming from collections of type C-of-T. > And why bring C++ into it? It's already there, you mentioned the pair of iterators, and there is std::max_element() which finds the greatest element in any range based solely on these, and optionally using a generic comparison. There are similar things in Dmitry's packages. A key difference seems to be that Ada's Cursors are tied to a specific collection. I don't know of any convenient way around this, maybe because type Cursor is just private in every Ada.Containers.Xyz and there is no common type name for them, or for what some algorithm might need them to have in common. I'm not sure if the new Ada.Iterator_Interfaces (LRM 5.5.1) could solve this, also because I really don't know that yet. But it looks like I'd need instances of specific containers for instantiation. (That being consistent with Ada's approach to the STL, I think.)