Control-Monad-MultiPass- A Library for Writing Multi-Pass Algorithms.

Safe HaskellSafe



The TopKnot instrument is used for knot tying across passes. It allows a value to be written during the epilogue of one pass and read during the prologue of a later pass. Knot tying is a technique sometimes used in lazy functional programming, in which the definition of a variable depends on its own value. The lazy programming technique depends on an implicit two-pass ordering of the computation. For example, the classic repmin program produces a pair of outputs - a tree and an integer - and there is an implicit two-pass ordering where the integer is computed during the first pass and the tree during the second. The TopKnot instrument allows the same technique to be applied, but the ordering of the passes is managed explicitly by the Control.Monad.MultiPass library, rather than implicitly by lazy evalution.



data TopKnot a r w p1 p2 tc Source

Abstract datatype for the instrument.


Instrument tc () () (TopKnot a r w Off Off tc) 

load :: TopKnot a r w p1 p2 tc -> MultiPassPrologue r w tc (p2 a)Source

Load the value that was stored during the first pass.

store :: TopKnot a r w p1 p2 tc -> p1 a -> MultiPassEpilogue r w tc ()Source

Store a value during the epilogue of the first pass. This function should be called exactly once.