开发者

Lookup on object of indeterminate type

I'm trying to figure out why this doesn't compile.

type A() =
  member __.M(f:DateTime -> seq<int>) 开发者_如何学Go= ()
  member __.M(f:DateTime -> obj) = ()

let a = A()
a.M(fun d -> seq [d.Year]) // 'd' is indeterminate type

If I remove the second overload or add a type annotation to d, it does. Is it because some aspect of overload resolution occurs prior to type checking?


Yes, basically overloads make type inference hard. In this case, it seems like you're hoping that the compiler will do some sort of generalization of the types DateTime -> seq<int> and DateTime -> obj to get DateTime -> ? and then proceed from there, but I don't think it ever does that kind of "anti-unification".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜