This page explains how to create, customize, and use updatable pretty-printers in Haskell, using the support offered by the Sdf2Haskell? generator of Strafunski.



The Haskell standard libraries come with a nice module of pretty-print combinators, originally devised by John Hughes and Simon Peyton-Jones (Text.PrettyPrint.HughesPJ). These combinators allow you to write a function of type X -> Doc to pretty-print values of type X to the abstract document type Doc. The obtained document of type Doc can subseqently be rendered to a String representation with a (parameterizable) render function.


Strafunski is a Haskell-based bundle for generic programming based on the notion of a functional strategy. A functional strategy is a function that is (i) generic, in the sense that it is applicable to values of any type, and (ii) updatable, in the sense that its generic behaviour can be specialized for specific types. For more info see the Strafunski home page.

Generic & updatable pretty-printers

On this page, we explain how Strafunski and pretty-printing combinators can be combined to allow one to construct pretty-printers that are:

  • generic, in the sense that they can pretty-print values of any type in a generic way,
  • updatable, in the sense that they can be customized with specific behaviour for values of specific types.

The solution involves a few additional combinators, that are available with Strafunski, and (optionally) some support from the Sdf2Haskell? generator, also available with Strafunski.