Walking along two lists #
Turing.MultiTapeTM.zipFold f p l r walks along l, consuming r in step, and collects
f p a b? for each element a of l and the matching element b? of r, if any — that is,
(l.zipWithLeft (f p) r).reduceOption (Turing.MultiTapeTM.zipFold_eq_zipWithLeft). The function
decides what happens at a missing partner and may drop an element, so that both zipping and
padding are instances.
A linear f gives a machine in time the length of l times the length of the input and in linear
space, provided that the results collected along the way are linear in the input. An f in linear
space, at any time, gives a machine within the input and a bound on those results. The machine
folds over l, keeping the rest of r and the results.
Main definitions #
Turing.MultiTapeTM.zipFold: walking along two lists.
Main results #
Turing.MultiTapeTM.zipFold_eq_zipWithLeft:zipFoldisList.zipWithLeftfollowed byList.reduceOption.Turing.MultiTapeTM.zipFold_some: a walk that keeps every element is aList.mapIdxreading the second list at each index.Turing.MultiTapeTM.ComputableInO.zipFold: the cost of walking along two lists.Turing.MultiTapeTM.ComputableInSpace.zipFold: the space of walking along two lists.
Turing.MultiTapeTM.zipFold is List.zipWithLeft followed by List.reduceOption.
A walk that keeps every element is a List.mapIdx that reads the second list at each index.
Walking along two lists. For a linear f, whose results collected along the way are
linear in the input, walking along two lists takes time the length of the first list times the
length of the input, and linear space.
The space of walking along two lists. For f in linear space, walking along two lists
takes space linear in the input and in a bound B on the results collected along the way.