title: How does Haskell printf work?
body: <p>Haskell's type safety is second <s>to none</s> only to dependently-typed languages. But there is some deep magic going on with <a href="http://hackage.haskell.org/packages/archive/base/latest/doc/html/Text-Printf.html" rel="noreferrer">Text.Printf</a> that seems rather type-wonky.</p>
  
  <pre><code>&gt; printf "%d\n" 3
  3
  &gt; printf "%s %f %d" "foo" 3.3 3
  foo 3.3 3
  </code></pre>
  
  <p>What is the deep magic behind this? How can the <code>Text.Printf.printf</code> function take variadic arguments like this?</p>
  
  <p><strong>What is the general technique used to allow for variadic arguments in Haskell, and how does it work?</strong></p>
  
  <p>(Side note: some type safety is apparently lost when using this technique.)</p>
  
  <pre><code>&gt; :t printf "%d\n" "foo"
  printf "%d\n" "foo" :: (PrintfType ([Char] -&gt; t)) =&gt; t
  </code></pre>