I get the value restriction error on let makeElem
in the following code:
let elemCreator (doc: XmlDocument) =
fun name (value: obj) ->
let elem = doc.CreateElement(name)
match value with
| :? seq<#XmlNode> as childs ->
childs |> Seq.iter (fun c -> elem.AppendChild(c) |> ignore)
elem
| _ -> elem.Value <- value.ToString(); elem
let doc = new XmlDocument()
let makeElem = elemCreator doc
Why I get the value restriction error if anonymous function returned from elemCreator
hasn't any generic parameters?
The compiler states that the infered type of makeElem is (string -> 'a -> XmlNode)
. But why it infers second parameter as 'a
if I've declared it as obj
?