为什么这样的代码不能编译?
type MyType() =
static member myMember (f,(g,h)) = g
static member myMember (a,(b,c,d)) = MyType.myMember(a,(b,c))
static member myMember (a,(b,c,d,e)) = MyType.myMember(a,(b,c))
它说:......元组有不同长度的2和4
这是一个错误?
答案 0 :(得分:3)
我不确定它是否是一个错误,但一般来说,存在多次重载时的类型推断很难做得很好。最好的办法是添加一些类型的注释:
type MyType() =
static member myMember<'a,'b,'c> (f:'a,(g:'b,h:'c)) = g
static member myMember (a,(b,c,d)) = MyType.myMember<_,_,_>(a,(b,c))
static member myMember (a,(b,c,d,e)) = MyType.myMember<_,_,_>(a,(b,c))