开发者

Lookup on object of indeterminate type

开发者 https://www.devze.com 2023-03-30 21:30 出处:网络
I\'m trying to figure out why this doesn\'t compile. type A() = member __.M(f:DateTime -> seq<int>) 开发者_如何学Go= ()

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

精彩评论

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

关注公众号