wait I think I got what you mean.
So every invocation is an expression
let a = 4 // Top level Expression 1
Console.log(55) // Top level Expression 2
Console.log("whatever") // Top level Expression 3
switch a {
| 4 => "four"
| _ => "not four"
}->Console.log // Top level Expression 4
let main = { // Like you said, think of it like let main = (_:'a){
let returnSelf = (x: 'a) => x
let print = (v:'a) => Console.log(v)
print(33) //here 'a is type int when it's called by Expression 6
returnSelf("ad")->Console.log //ERR, because 'a is int now in Expression 6 main()invocation
} // Top level Expression 5
main() // Top level Expression 6
So at each of those top level expression, they get 1 type
for the type variable 'a
.
Top Level Expression 6 is main()
invocation, it will get one type 'a
that will be inferred as int
due to its first usage.
THANK YOU!! I think it finally makes sense.