當我有這樣的代碼:創建遞歸識別聯合值
type HtmlNode =
| HtmlElement of name:string * attribute:HtmlAttribute list
| HtmlText of content:string
and HtmlAttribute =
| HtmlAttribute of name:string * value:string * parent:HtmlNode
let createElement name attrs =
let toAttributes element = [ for name, value in attrs -> HtmlAttribute(name, value, element)]
let rec element = HtmlElement(name, attributes)
and attributes = toAttributes element
element
編譯器提供了以下錯誤:
Recursive values cannot appear directly as a construction of the type 'HtmlNode' within a recursive binding. This feature has been removed from the F# language. Consider using a record instead.
這是爲什麼? [讓REC應該支持遞歸值,並與記錄的類似的東西作品的創作。
我沒有得到這個錯誤。 – eulerfx
基於消息,這在最近的3.1版可能已被更改。發生 – Daniel
同樣的錯誤在F#3.0 - 所以它是年齡稍大的 –