Having a C# class like
public abstract class ValueAttrProxy<T> : IAttrProxy where T : IEquatable<T>
{
public T Value { get; }
...
}
in F# when I try to pattern match it like so:
let attrValue (attr:IAttrProxy) =
match attr with
| :? ValueAttrProxy<'a> as attr -> attr.Value.ToString()
The type inference seems to work, but sending to interactive fails with the following error:
error FS0071: Type constraint mismatch when applying the default type 'IEquatable<'a>' for a type inference variable. The types ''a' and 'IEquatable<'a>' cannot be unified. Consider adding further type constraints
I am a bit stumped what is the problem, or where is the additional type annotation is expected.
Trying to specify IEquatable<'a> in the matching pattern like
| :? ValueAttrProxy<IEquatable<'a>> as attr -> attr.Value.ToString()
then even the type inference fails, and underlines the pattern with the same error message. If I constrain the generic parameter to a specific type like int, then it works, but the point is that I just want the string representation of the Value, regardless of what its actual type is.