My question is somewhat related to this one - Functions with generic parameter types - but I can't quite work out how to do what I want.
I want to define a 'descendants function to wrap the call to 'Descendants' on various C# classes like so:
let descendants name (xDocument:XDocument) = xDocument.Descendants name
let descendants name (xElement:XElement) = xElement.Descendants name
This approach doesn't work because we have a duplicate definition of 'descendants'.
I thought it would be possible to make use of the inline function and statically resolve parameters to define the following method to do this instead:
let inline descendants name (xml : ^x when ^x : (member Descendants : XName -> seq<XElement>)) =
xml.Descendants name
But I'm getting this error when trying to do that:
Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.
Is there a way that I can write that second function to do what I want?