Jomo Fisher–I was curious about type inference in F# and I wondered what would happen if there was really no way for the compiler to infer a type. Consider this function which takes a value and just returns it:
let func n = n
Like last time, I compiled this with fsc.exe. I was expecting a polite error message saying the type of ‘n’ couldn’t be determined. Instead, compilation succeeded. The result was equivalent to this C#:
In retrospect, this makes complete sense. Of course an unknown type should be inferred to be a template type. So far, F# seems to do a good job of being concise for a strongly typed language.
This posting is provided “AS IS” with no warranties, and confers no rights.