External Publication
Visit Post

Lazily consuming a self-referential linked list

Haskell Community [Unofficial] May 19, 2026
Source

Reasoning about self-recursive types for a second, does it make sense that a self-recursive type can completely consume itself?

If we take just a typical infinite list, we know that we cannot guarantee that we process all of it; we must either work on only some subset of it (take a prefix or search through it), or perform an operation that occurs over the entire list lazily (fmap or foldr with a function lazy in the second argument).

What you’re trying to do here is produce a potentially infinite list as well as consume it in its entirety, and I think that that has issues.

I spent some time trying to use lazy writer and Endo to get some “efficient” concatenation but kept running up against looping code and end of list evaluations. I’d be interested in a solution if someone finds one!

Discussion in the ATmosphere

Loading comments...