Journal of Functional Programming

Functional Pearls

Linear, bounded, functional pretty-printing

S. DOAITSE SWIERSTRAa1 and OLAF CHITILa2

a1 Utrecht University, The Netherlands

a2 University of Kent, UK

Abstract

We present two implementations of Oppen's pretty-printing algorithm in Haskell that meet the efficiency of Oppen's imperative solution but have a simpler and a clear structure. We start with an implementation that uses lazy evaluation to simulate two co-operating processes. Then we present an implementation that uses higher-order functions for delimited continuations to simulate co-routines with explicit scheduling.