To demonstrate derivation of monadic programs, we present a specification of sorting using the non-determinism monad, and derive pure quicksort on lists and state-monadic quicksort on arrays. In the derivation one may switch between point-free and pointwise styles, and deploy techniques familiar to functional programmers such as pattern matching and induction on structures or on sizes. Derivation of stateful programs resembles reasoning backwards from the postcondition.
翻译:为了展示蒙拿迪程序衍生,我们提出了一个使用非确定性山岳来分类的规格,并且从列表和阵列上产生纯等离子体,并在阵列上产生纯等离子体。 在引出时,我们可以在点和点风格之间转换,并运用功能程序员熟悉的技术,如结构或大小上的模式匹配和感应。 典型程序的推理类似于后条件的倒推理。