title: Generating F# code
body: <p>T4 is the "official" code generation engine for C#/VB.NET. But <a href="http://cs.hubfs.net/forums/thread/10139.aspx" rel="noreferrer">F# doesn't support it</a> (this is from April, but I couldn't find any newer mentions). So what is a good way to generate F# code?</p>
  
  <p>EDIT:</p>
  
  <p>I want to implement <a href="http://www.soi.city.ac.uk/~ross/papers/FingerTree.html" rel="noreferrer">2-3 finger trees</a> in F#. I already have implemented them in C#, so this should be a nice comparison. The "digits" and nodes of the tree can be represented as arrays, so</p>
  
  <pre><code>type 't FingerTree = Empty | Single of 't | Deep of 't array * (('t FingerTree) array) lazy * 't array
  </code></pre>
  
  <p>However, the maximum size of these arrays is very small, so it'd be nice to have</p>
  
  <pre><code>type 't Digit = Digit1 of 't | Digit2 of 't*'t | Digit3 of 't*'t*'t | Digit4 of 't*'t*'t*'t
  type 't Node = Node2 of 't FingerTree * 't FingerTree | Node3 of 't FingerTree * 't FingerTree * 't FingerTree 
  type 't FingerTree = Empty | Single of 't | Deep of 't Digit * ('t Node) lazy * 't Digit
  </code></pre>
  
  <p>to avoid bounds checking, etc.</p>
  
  <p>But then writing all functions on Digit and Node by hand becomes more difficult, and it's better to generate them. And a T4-like approach looks perfect for it...</p>