Riddle me this

Posted in haskell
5 comments on “Riddle me this
  1. sclv says:

    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.

  2. brian says:

    Don’t forget package ‘xformat’.

  3. Saizan says:

    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.

  4. Saizan: Wow, that’s impressive. Type signatures longer than the code they describe? Eeek!

  5. Saizan says:

    well, the typeclass system is what’s doing most of the work :P

1 Pings/Trackbacks for "Riddle me this"
  1. [...] 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 [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>