当我有这个代码时:
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
编译器给出以下错误:
递归值不能直接作为递归绑定中“HtmlNode”类型的构造出现。此功能已从 F# 语言中删除。考虑改用记录。
这是为什么?let rec 应该支持递归值的创建,并且类似的东西适用于记录。