Ancestors

Toot

Written by Csepp 🌢 on 2025-01-05 at 03:45

Can you express streams / lazily evaluated lists with an eagerly evaluated fold combined with a continuation in #Scheme / #OCaml / other languages with some form of continuations? :flan_think:

And if so, are there existing libraries that build on this?

I'm pretty sure it's possible, at least with unconstrained call/cc, not quite sure about more restricted variations, or how it would work with typing.

I'd try to prototype it myself but I have my final exam coming up, so I hope tooting about it is enough to get it out of my system. :neofox_laugh_sweat:

cc: #compsci

=> More informations about this toot | More toots from csepp@merveilles.town

Descendants

Written by Bad Diode on 2025-01-05 at 08:34

@csepp hmm not sure, if the fold is eager how could it reduce a lazy list? The cc could probably be used to implement a lazy fold but not quite sure they can be combined like that unless the fold blocks as well while waiting. Not a big cc user or anything and also maybe I misinterpreted your Q, but curious about other answers

=> More informations about this toot | More toots from bd@merveilles.town

Written by Csepp 🌢 on 2025-01-05 at 13:37

@bd Well, you can implement return in terms of call/cc (it's one of the canonical examples), so all you would need (in theory, I haven't tested this) is to know when to return from the fold.

=> More informations about this toot | More toots from csepp@merveilles.town

Written by Edwin Török on 2025-01-05 at 10:18

@csepp The stream needs to be finite for the fold to finish. If you define your stream by its fold function (push) then it is trivial: you supply your fold function as argument to the stream. https://github.com/odis-labs/streaming/blob/08c2d6329ad4a4059eefcd196a4209d16130241c/streaming/Stream.ml#L125 https://github.com/odis-labs/streaming/blob/08c2d6329ad4a4059eefcd196a4209d16130241c/streaming/Stream.ml#L79 https://github.com/odis-labs/streaming/blob/08c2d6329ad4a4059eefcd196a4209d16130241c/streaming/Sink.ml#L320 In some way this is similar to CPS: each stream waits for the fold function of the next stream, until you supply a final Sink.

For a pull style stream you'll need to loop https://github.com/odis-labs/streaming/blob/08c2d6329ad4a4059eefcd196a4209d16130241c/streaming/Source.ml#L176, although this relies on imperative code then. You can transform a lazy list into a pull style stream that forces one cell at a time. No call/cc needed.

=> More informations about this toot | More toots from edwintorok@discuss.systems

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113773690070706555
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
235.766918 milliseconds
Gemini-to-HTML Time
0.903149 milliseconds

This content has been proxied by September (ba2dc).