comp.lang.ada
 help / color / mirror / Atom feed
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: project euler 26
Date: Sat, 09 Sep 2023 22:04:34 +0100	[thread overview]
Message-ID: <87sf7nkqhp.fsf@bsb.me.uk> (raw)
In-Reply-To: udh9fo$3vtq2$1@dont-email.me

"G.B." <bauhaus@notmyhomepage.invalid> writes:

> On 08.09.23 23:02, Ben Bacarisse wrote:
>> "G.B." <bauhaus@notmyhomepage.invalid> 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.

The "max so far" function is not being composed.

> 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?

I am not sure how the discussion got here.  Ada is an imperative
language so of course one would use "running" state to calculate a
maximum.  The max_of_F_over_X function just loops like any other loop
from First_Of(X) to Last_Of(X) calculating F(This(X)), comparing that
with Max_So_Far.

These are invented names, of course, because I don't know how it should
be done, but the idea is plain imperative code.  In fact, it's possible
that Ada has some entirely different syntax for this kind of imperative
loop.

The "fix" to use a composed function was because one proposed solution
found the maximum of Element(C) (where C was a cursor) because Element
was passed as F, but that of course is not what was wanted.  To find the
maximum of F I speculated that one could pass F.Element.

>>> 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.

Given the above confusion about what is being composed, I can see the
connection with monads.  But there is no reason to use the concept of a
monad in a language with modifiable state.  The maximum should be found
as in the posted code with a simple loop.

> 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.)

Thanks for the pointer.  I am not sure I have time to look in detail,
but it looks interesting.

-- 
Ben.

  reply	other threads:[~2023-09-09 21:04 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-04  9:19 project euler 26 CSYH (QAQ)
2023-09-04 11:06 ` Niklas Holsti
2023-09-04 12:39   ` Dmitry A. Kazakov
2023-09-04 16:01     ` Ben Bacarisse
2023-09-04 19:20       ` Dmitry A. Kazakov
2023-09-04 20:18         ` Ben Bacarisse
2023-09-04 21:00           ` Dmitry A. Kazakov
2023-09-04 23:16             ` Ben Bacarisse
2023-09-05  7:23               ` Dmitry A. Kazakov
2023-09-05 15:18                 ` Ben Bacarisse
2023-09-05 17:08                   ` Dmitry A. Kazakov
2023-09-06  1:10                     ` Ben Bacarisse
2023-09-06  7:06                       ` Dmitry A. Kazakov
2023-09-06 15:16                         ` Ben Bacarisse
2023-09-06 15:54                           ` Dmitry A. Kazakov
2023-09-06 23:32                             ` Ben Bacarisse
2023-09-07  9:02                               ` Dmitry A. Kazakov
2023-09-08  1:32                                 ` Ben Bacarisse
2023-09-08  7:23                                   ` Dmitry A. Kazakov
2023-09-09  0:25                                     ` Ben Bacarisse
2023-09-09  9:32                                       ` Dmitry A. Kazakov
2023-09-10  1:20                                         ` Ben Bacarisse
2023-09-10  8:46                                           ` Dmitry A. Kazakov
2023-09-10 19:22                                             ` Ben Bacarisse
2023-09-11  6:53                                               ` Dmitry A. Kazakov
2023-09-11 16:13                                                 ` Ben Bacarisse
2023-09-12  7:17                                                   ` Dmitry A. Kazakov
2023-09-13 12:24                                                     ` Ben Bacarisse
2023-09-14  6:33                                                       ` Dmitry A. Kazakov
2023-09-14 14:30                                                         ` Ben Bacarisse
2023-09-08  6:09                               ` G.B.
2023-09-08 21:02                                 ` Ben Bacarisse
2023-09-09  8:13                                   ` G.B.
2023-09-09 21:04                                     ` Ben Bacarisse [this message]
2023-09-10  9:11                                     ` Dmitry A. Kazakov
2023-09-05 17:35                 ` moi
2023-09-04 14:23 ` Dmitry A. Kazakov
2023-09-07  7:31 ` Francesc Rocher
2023-09-15  9:07   ` CSYH (QAQ)
2023-09-19  7:59     ` comp.lang.ada
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox