How to check if a function's type parameters are statically resolved?

白昼怎懂夜的黑 提交于 2019-12-22 09:48:19

问题


very simple examples:

  1. let myfun x = x
    Here in the intellisense it says "x: 'a -> 'a". In the FSI it says "x: 'a -> 'a"
  2. let inline myfun x = x
    Here in the intellisense it says "x: 'a -> 'a". In the FSI it says "x: 'a -> 'a" <<<< why not ^a?
  3. let inline myfun (x: 'b) = x
    Here in the intellisense it says "x: 'b -> 'b". In the FSI it says "x: 'b -> 'b"
  4. let inline myfun (x: ^b) = x
    Here in the intellisense it says "x: 'b -> 'b". In the FSI it says "x: ^b -> ^b" <<<< different

Since the intellisense never shows ^b, should I look for ^b as an indicator of "statically resolved" in FSI?

Does inline guarantee "statically resolved"?


回答1:


Inline does allow but does not force statically resolved types, that's why in case 2. it remains the same as in case 1. I think in most cases type inference is smart enough to guess if the type should really be statically resolved, even if you don't specify the ^.

For example if you change your function body to sqrt x in case 3. you'll get

> let inline myfun (x: 'b) = sqrt x;;
val inline myfun :  ^b ->  ^a when  ^b : (static member Sqrt :  ^b ->  ^a)

I personally always try not to specify types explicitly at first try, then I check if I'm happy with the inference, if I'm not then I try adding inline, but not the hat types.

Why intellisense shows sometimes something different? that's probably a small bug.



来源:https://stackoverflow.com/questions/16327655/how-to-check-if-a-functions-type-parameters-are-statically-resolved

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!