{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreie7wjbamjdmrccdm2nnzjnszgzeydirnev35umv7slp7nudwai26y",
    "uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mmnouge2bxr2"
  },
  "path": "/t/lazily-consuming-a-self-referential-linked-list/14131#post_15",
  "publishedAt": "2026-05-25T04:25:19.000Z",
  "site": "https://discourse.haskell.org",
  "tags": [
    "@VegOwOtenks",
    "recursion-schemes package"
  ],
  "textContent": "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:\n\nVegOwOtenks:\n\n> `j -> m (Seq j, a)`\n\nIf you tease the type a bit you end up with a co-algebra:\n\n\n    -- type JobF m a = m :.: (,) a :.: Seq\n    -- or, inlining, composition...\n    data JobF m a j = JobF { unJobF :: m (a, Seq j) }\n      deriving (Functor)\n\n\ngiven 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).\n\nI 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?",
  "title": "Lazily consuming a self-referential linked list"
}