The following works perfectly, as one would expect in a polymorphic Curry-type system, where, for example, the identity function is actually an infinite family of functions, one for each type "a β a:
let fx = x printfn "%A" (f 2) printfn "%A" (f 3.4)
But when we try to do something more complex, it fails in the third line, "this expression should have int type, but there is a float type here":
let fx = string x printfn "%A" (f 2) printfn "%A" (f 3.4)
(But commenting on the second line does the work of the third line, as expected.)
A priori, I would expect that type inference will either behave in Curry style, where the undefined type is actually common, or block only one version of the function, but as far as I can see, it does the first in the first case, and the second in the second case . I assume that there is some logic of behavior that I simply do not collect. What am I missing?
source share