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 $\mathit{scanl}$-like predicate. We develop theorems that convert a variation of $\mathit{scanl}$ to a $\mathit{foldr}$ that uses the state monad, as well as theorems constructing hylomorphism. The algorithm is used to solve the $n$-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.
翻译:等量推理是功能性编程提供的最重要工具之一。 奇怪的是, 相对较少的注意力被放在关于monadic 程序的推理上。 在本报告中, 我们为使用monadic 展出以产生可能的解决方案的麻烦规格获取回溯跟踪算法, 这些参数使用 $\ mathit{ scanl} 类似前提过滤。 我们开发了将 $\ mathit{ scanl} $ 转换为 $\ mathit{ foldr} $ 的理论, 使用 monad, 以及 建立旋写主义的理论。 该算法用于解决 $n- queens 的谜题, 我们的运行例子。 目的是开发用于生成 monadic 程序的方法和模式, 侧重于国家与非定义之间的复杂互动 。