Lazily consuming a self-referential linked list
VegOwOtenks:
run :: [q] -> s -> (q -> s -> [q] -> ([q], s)) -> s
This looks to me as if the [q] is really part of the state being modified:
data PipelineState = PS {globalState :: s, jobs :: [q]}
run :: PipelineState -> (q -> PipelineState -> PipelineState) -> s
and supposedly the final s is really a PS s [], no more jobs to do. Now I wonder: Why does the action argument of run have an extra q argument at all, when it could pop one off the [q]? Perhaps that is the missing occasion for pattern-matching on the empty list? So suppose you could merge run and go into a single recursive function that does not need the extra q for non-emptyness. Suppose further that we agree the final state is just a special PipelineState. Now a function with the signature
run :: x -> (x -> x) -> x
looks like something that seeks the least fixed point of an endo-function above a given starting value, as per Kleene’s fixed point theorem.
Discussion in the ATmosphere