External Publication
Visit Post

Lazily consuming a self-referential linked list

Haskell Community [Unofficial] May 19, 2026
Source
Just process the batches explicitly instead of knot-tying? run :: [q] -> s -> (q -> s -> [q] -> ([q], s)) -> s run initial state action = loop initial state where loop [] s = s loop qs s = case go qs s action of ([], s') -> s' (qs', s') -> loop qs' s' go :: [q] -> s -> (q -> s -> [q] -> ([q], s)) -> ([q], s) go qs s0 f = case qs of [] -> ([], s0) q:rest -> let (qs1, s1) = f q s0 qs2 (qs2, s2) = go rest s1 f in (qs1, s2) Not sure if that’s what you want, it’s a bit hard to tell without examples. The code was produced by GPT-5.5.

Discussion in the ATmosphere

Loading comments...