{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreifqf5d66povkqonc6uedaqvfh7ja2msqjlz4nwp5z4acf43qchzl4",
    "uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mmavmyhvmv22"
  },
  "path": "/t/lazily-consuming-a-self-referential-linked-list/14131#post_12",
  "publishedAt": "2026-05-20T01:34:53.000Z",
  "site": "https://discourse.haskell.org",
  "textContent": "VegOwOtenks:\n\n> My only idea is a counter which keeps track of how many items were consumed/generated (it is possible to keep track of this.), list evaluation would immediately stop when the counter reaches zero. But this feels like cheating.\n\nSince you seem to really like lists, you could use another list as a counter\n\n\n    run :: [q] -> s -> (q -> s -> ([q], s)) -> s\n    run initial state action =\n      let (qs, state') = go initial (initial ++ qs) state\n      in state'\n      where\n        go [] _ s0 = ([], s0)\n        go (_:counter) (q:rest) s0 =\n          let (newq, s1) = action q s0\n              (qs', s2) = go (newq ++ counter) rest s1\n          in (newq ++ qs', s2)\n",
  "title": "Lazily consuming a self-referential linked list"
}