Generally speaking, I think that hat types such as ^x can be used too much (at least judging by the number of questions about them in SO). This is a powerful feature, but it was designed primarily to solve problems with general arithmetic. I think they can make F # programs unnecessary.
If you work only with XDocument and XElement , then the answer is quite simple, because you can use XContainer , which is their common base class, and has a Descendants method:
let descendants name (xml:XContainer) = xml.Descendants(name)
If you cannot find a common base class, you can, of course, use the ^a type, but you can also use the usual overload, which is possible in F #, but only works for members of the object type:
type Xml = static member Descendants(name, x:XDocument) = x.Descendants(name) static member Descendants(name, x:SomeOtherClass) = x.SomeOtherDescendants(name)
(Since you referred to a question with an answer that already shows that overloading works with members, this is probably not new to you, but may be useful to others who find this question in the future).
Tomas Petricek Feb 14 '10 at 13:30 2010-02-14 13:30
source share