colinfang
colinfang

Reputation: 21727

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

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"?

Upvotes: 3

Views: 250

Answers (1)

Gus
Gus

Reputation: 26174

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.

Upvotes: 1

Related Questions