T4是C#/ VB.NET的「官方」代碼生成引擎。但F# doesn't support it(這是從四月,但我找不到任何新的提及)。那麼生成F#代碼的好方法是什麼?生成F#代碼
編輯:
我想要實現在F#2-3 finger trees。我已經在C#中實現了它們,所以這應該是一個很好的比較。該樹的「數字」和節點可以表示爲數組,所以
type 't FingerTree = Empty | Single of 't | Deep of 't array * (('t FingerTree) array) lazy * 't array
然而,這些陣列的最大尺寸非常小,所以它會是不錯的
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
爲了避免邊界檢查等
但隨後手寫上的數字和節點的所有功能變得更加困難,這是更好地生成它們。而T4式的方法看起來非常完美...
我就扔[這](https://github.com/kerams/Templatus)在那裏。這是我最近一起入侵的東西。 – nphx 2016-01-25 10:15:06