I'm working through this F# wikibook and I'm confused at something I'm seeing in the function composition section of the linked page.
The simplest example I can come up with follows:
// int -> int
let f x = x + x
// float -> float
let g x = x + 1.0
This is fine. I understand the types of these functions easily and I can run them in fsi and confirm that they take and return values of the types I've called out above.
If I add the following line, then I see the change I'm not so sure I understand.
// equivalent to f (g x)
let fog = f << g
The way I understand this, it shouldn't work because f expects an int, but g returns a float.
If I define this composition in fsi, I get the expected type error. If I put all these in a .fsx file and send the whole thing to fsi, the signature of f becomes float -> float.
I am confused as to the following:
- scope of the type inference happening?
- what is different between defining these in a file and in fsi?
I have tried searching, but I don't know enough at this point to effectively find answers to these questions. I'll be happy to RTFM if you can help point me to the parts that address these.
float->float. You might be testing the wrong way. Please check again. - Gus