Subscribe to
Posts
Comments

Riddle me this

6 Responses to “Riddle me this”

  1. on 25 Sep 2009 at 15:51sclv

    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. on 26 Sep 2009 at 00:09brian

    Don’t forget package ‘xformat’.

  3. on 26 Sep 2009 at 00:38Saizan

    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. on 26 Sep 2009 at 12:40Bryan O'Sullivan

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

  5. on 26 Sep 2009 at 12:46Saizan

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

  6. [...] 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