5 comments on “Riddle me this”
1 Pings/Trackbacks for "Riddle me this"
-
[...] little while ago, Bryan O’Sullivan was developing his Criterion benchmark suite, and had trouble with using the Text.Printf module in a monad transformer on top of IO. I thought I knew how to solve this, but my first idea didn’t work — and nor did my [...]

this is a terrible hack, but no more of a hack than printf itself:
test :: (HPrintfType r, NoOp r) => Bool -> Handle -> String -> r
test b = if b then hPrintf
else nopr
class NoOp a where
nopr :: a
instance NoOp (IO a) where
nopr = return undefined
instance (NoOp r) => NoOp (a -> r) where
nopr = const $ nopr
don’t have an answer for the second bit at the moment tho.
Don’t forget package ‘xformat’.
I got a solution requiring more extensions but that it looks more general, here’s the paste:
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=9857
The types, especially those inferred like in test, aren’t so pretty but not horrible either.
Saizan: Wow, that’s impressive. Type signatures longer than the code they describe? Eeek!
well, the typeclass system is what’s doing most of the work