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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to