[Haskell-cafe] Text formatting question

Evan Klitzke evan at eklitzke.org
Thu Jun 4 03:41:17 EDT 2009


I'm writing code with hslogger, and I'm finding myself frequently
writing things like this:

infoM $ printf "%s saw %s with %s" (show x) (show y) (show z)

On #haskell I asked about why you can't have use %s with any instance
of (Show a), and augustss, the Text.Printf maintainer, pointed out
that it's not possible in Haskell 98 because of overlapping instances.
So I'm trying to figure out the best way to work around this in my
code. Some of the logging statements can get kind of long, so the
ability to elide the calls to `show` would be nice. So what's the best
way to do this?

I was thinking of making my own variant of printf that only accepted
the %s formatter and took (Show a)'s as arguments, but there might be
a simpler way? Another thing is the code is already fairly GHC
specific at this point, so if there are GHC extensions that might be
useful here that I don't know about, I'm interested in hearing about
them.

Thanks.

-- 
Evan Klitzke <evan at eklitzke.org> :wq


More information about the Haskell-Cafe mailing list