[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:

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

Wrong arg types or wrong printf arg count will result in compile time

Marc Weber

More information about the Haskell-Cafe mailing list