{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreigeu4dsumum5fhtudlnlcpyqbb4753645ocfovopgzcbd2e26rz3m",
    "uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mm6yopxjh4g2"
  },
  "path": "/t/lazily-consuming-a-self-referential-linked-list/14131#post_2",
  "publishedAt": "2026-05-19T08:23:56.000Z",
  "site": "https://discourse.haskell.org",
  "textContent": "VegOwOtenks:\n\n>\n>     go :: [q] -> s -> (q -> s -> [q] -> ([q], s)) -> ([q], s)\n>     go qs s0 f = case qs of\n>       [] -> ([], s0)\n>       q:rest -> let\n>           (qs1, s1) = f q s0 qs2 -- why is this qs2 and not rest?\n>           (qs2, s2) = go rest s1 f -- why is this rest and not qs1?\n>         in (qs1, s2) -- why is this qs1 and not qs2?\n>\n\nI think you could condense `go` to look something like:\n\n\n    go :: [q] -> s -> (q -> s -> [q] -> ([q], s)) -> ([q], s)\n    go qs s0 f = case qs of\n      [] -> ([], s0)\n      q:rest -> let\n          (qs1, s1) = f q s0 rest\n          newQ = rest ++ qs1\n          in go newQ s1 f\n\n\n\nUnless I’m missing something.\n\nYour original approach causes an infinite loop because the recursive call to `go` depends on `s1` whose result depends on `qs2` which is produced by `go`.",
  "title": "Lazily consuming a self-referential linked list"
}