External Publication
Visit Post

Lazily consuming a self-referential linked list

Haskell Community [Unofficial] May 19, 2026
Source

Perhaps you just want this?

run :: (s -> q -> (s, [q])) -> s -> [q] -> s
run _ s [] = s
run f s qs = case mapAccumL f s qs of
  (s', qss) -> run f s' (concat qss)

The concatenation is properly oriented so it’s effectively free.

Discussion in the ATmosphere

Loading comments...