[Haskell-cafe] ANN: Printf-TH

Marc Weber marco-oweber at gmx.de
Sat Jun 14 14:08:28 EDT 2008


Igloo (Ian Lynagh) allowed me kindly taking over maintainance on his
printf library using template haskell written in 2003. I've updated it
so that it compiles with ghc-6.8.2.
You can get it from hackage:
 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Printf-TH

usage looks like this:

{-# OPTIONS_GHC -XTemplateHaskell #-}
...
import Language.Haskell.TH.Syntax
import Text.Printf.TH (printf)

...
            putStrLn $ $(printf "Foo %H bar") (Just 5)
            putStrLn $ $(printf "%6d") 1
            putStrLn $ $(printf "%6d") (-1)

Short Explanation:
$(printf "%d") will be replaced by a auto generated function taking an int etc

Benefit:
Wrong arg types or wrong printf arg count will result in compile time
errors.

Enjoy
Marc Weber


More information about the Haskell-Cafe mailing list