title: How do I customize output of a custom type using printf?
body: <p>I've read through a good chunk of <em>Expert F#</em> and am working on building an actual application.  While debugging, I've grown accustomed to passing fsi commands like this to make things legible in the repl window:</p>
  
  <pre><code>fsi.AddPrinter(fun (x : myType) -&gt; myType.ToString())
  </code></pre>
  
  <p>I would like to extend this to work with the printf formatter, so I could type e.g.</p>
  
  <pre><code>printf "%A" instanceOfMyType 
  </code></pre>
  
  <p>and control the output for a custom type.  The book implies that this can be done (p 93, "Generic structural formatting can be extended to work with any user-defined data types,
  a topic covered on the F# website"), but I have failed to find any references as to how to actually accomplish this.  Does anyone know how? Is it even possible?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I should have included a code sample, it's a record type that I'm dealing with, e.g.</p>
  
  <pre><code>type myType = 
      {a: int}        
      override m.ToString() = "hello"
  
  let t = {a=5}
  printfn "%A" t
  printfn "%A" (box t)  
  </code></pre>
  
  <p>both print statements yield:</p>
  
  <pre><code>{a = 5;}
  </code></pre>