What would the F# equivalent of this bit of C#:
public T GetNewItem()
{
return new T();
}
In addition 开发者_开发知识库how would you return the new T() as a ref cell for usage in a .Net library requiring an out or ref parameter?
I think something as simple as this would work:
let getNewItem() = new 'T()
It infers the default constructor constraint.
let mutable d = getNewItem() //d inferred to be System.DateTime
DateTime.TryParse("1/1/2011", &d)
精彩评论