I deliberately added x to the end of this function
let myMax x y =
if x > y then x else y
x
I was expecting that x and y arguments are still of ‘a type, but I get this signature instead:
myMax : x:unit -> y:unit -> unit
Why these arguments inferred to have a unit type?
Edit: Thank you @gilles for the answer. Consider these two functions:
let foo x y =
0 // warning
x
val foo : x:'a -> y:'b -> 'a
let foo2 x y =
if x > y then x else y // no warning
x
val foo2 : x:unit -> y:unit -> unit
What makes the two signatures different? Seems like in the second function the compiler interpret the result of the comparison –either x or y- as unit
ignore
, chances are, you're doing something wrong. This particular example is not an exception either: theif-then
expression doesn't make any sense, because its return value is thrown away and it doesn't produce any side effects. – Ozonide