When do stateful traversals fuse?
Abstract
Gibbons and Oliveira proved that two monadic traversals fuse, , when the monad is commutative. The state monad is not commutative, so for stages that share a state the equation has to be checked pipeline by pipeline. We ask how hard this check is. Each stage is a total function given by a table over a finite state set and finite element types, and the two programs must return the same list and the same final state. An unsafe pipeline of stages over states has a counterexample of length at most , a breadth-first search finds a shortest one, and for every fixed safety at a given initial state is -complete. If every element type is a singleton, safety is -complete, also for pipelines described by straight-line grammars. For binary elements there is a fixed library of stages over a fixed state set for which safety is -complete, and -complete for pipelines described by grammars; the lower bounds come from the word problem of an automaton group. Two stages over two states generate pipelines with stages whose shortest counterexamples have length exactly . One of these stages commutes with itself but does not fuse with itself, a counterexample of minimal size to the conjecture of Gibbons and Oliveira that commuting Kleisli arrows fuse; over two states and two letters the conjecture fails for 156 of the 256 stages. Three idempotent stages over four states fuse in pairs but not together, and no three stages over three states with singleton elements behave this way. Bounded testing, commutation and pairwise checks therefore cannot validate the fusion of stateful traversals, whereas an exact check is tractable for a fixed number of stages.
Create a lesson
Metadata
- Categories
- cs.PL, cs.CC, cs.FL, cs.LO
Related papers
Rewinding the Fold: Making Stateful Computations Retractable
Shared title terminologycs.PLZiteng Wang, Linus Zheng, Dixin Tang et al.
Iris on Indirection Theory: Lightweight Higher-order Ghost State
Shared title terminologycs.PLDarius Foo, Viet-Anh Nguyen, Wei-Ngan Chin
On the Expressive Power of Hook-Indexed State: Comprehending State in the React UI Library (Extended Version)
Shared title terminologycs.PLToby Ueno, Ezra Cooper, Simon Fowler et al.