External Publication
Visit Post

Lazily consuming a self-referential linked list

Haskell Community [Unofficial] May 25, 2026
Source

Hopefully this isn’t reviving a dead topic but @VegOwOtenks I thought this was quite an interesting problem for me given that I enjoy recursion schemes too much. So, if I may chime in:

VegOwOtenks:

j -> m (Seq j, a)

If you tease the type a bit you end up with a co-algebra:

-- type JobF m a = m :.: (,) a :.: Seq
-- or, inlining, composition...
data JobF m a j = JobF { unJobF :: m (a, Seq j) }
  deriving (Functor)

given this your function type above becomes: j -> JobF m a j which for some fixed monad m and fixed a we get a co-algebra (JobF m a is a functor). What you have then described seems to be a at least a monadic anamorphism (or g-anamorphism with a monad distributive law if you’re using the recursion-schemes package).

I took a look at your nested mutual recursion functions by re-writing go and run using a Reader-State monad and using mfix. I haven’t come to any conclusions yet but I have a hunch that your problems sounds very similar to some other problems I solve that involve obtaining values “from the future”. Mind if you share your new definitions of WorkList.run and friends?

Discussion in the ATmosphere

Loading comments...