1. 7
  1.  

  2. 1

    I wonder if this could be made prettier with a little bit of Template Haskell and quasiquotation. In particular, could we replicate the nice syntax of printf that everyone is used to with formatting, and have it actually be commonly used and somewhat well-known? I would envision something along these lines:

    print [|Person's name is %s, age is %d|] "Dave" 54
    

    I also wonder whether having print be polymorphic in its output type is a good thing. printf is, which allows it to be used as both printf and sprintf from C, but I’m not sure how much of a benefit that really is (and it means that you sometimes need extra type signatures). On the other hand, being able to use printf to output String, Text, and ByteString (of both variants) might be nice.

    Also, note that the technical aspect of this idea is fairly simple – it’s probably already been implemented a half dozen times. The template haskell paper even uses it as an example and motivation for Template Haskell and shows a simple implementation. However, pulling in quasiquotes or Template Haskell to a new project always feels like a big decision, and so it’d rarely be used just for printf.