English

Calculating a backtracking algorithm: an exercise in monadic program derivation

Programming Languages 2021-01-26 v1

Abstract

Equational reasoning is among the most important tools that functional programming provides us. Curiously, relatively less attention has been paid to reasoning about monadic programs. In this report we derive a backtracking algorithm for problem specifications that use a monadic unfold to generate possible solutions, which are filtered using a scanl\mathit{scanl}-like predicate. We develop theorems that convert a variation of scanl\mathit{scanl} to a foldr\mathit{foldr} that uses the state monad, as well as theorems constructing hylomorphism. The algorithm is used to solve the nn-queens puzzle, our running example. The aim is to develop theorems and patterns useful for the derivation of monadic programs, focusing on the intricate interaction between state and non-determinism.

Keywords

Cite

@article{arxiv.2101.09409,
  title  = {Calculating a backtracking algorithm: an exercise in monadic program derivation},
  author = {Shin-Cheng Mu},
  journal= {arXiv preprint arXiv:2101.09409},
  year   = {2021}
}
R2 v1 2026-06-23T22:26:39.432Z