Here I have a function. In line List.append [0] free_list it is complaining that, This expression was expected to have type unit but here has a type 'a list, and it is not clear for me how does it infer that this statment must have an unit type.
let free_list=[]
let find_free_spaces :List<int>=
if 1=1 // The condition is not important
then List.append [0] free_list
free_list
In F#,
if/thenandif/then/elseare expressions, not statements (if you're coming from C#,if x then y else zis likex ? y : z). If there's anelseclause, then the type of that branch must match the type of theifbranch so that the whole expression is well-typed. If there is noelse, then theif's body must have typeunit, since otherwise the result would just be disregarded (basically,if x then yis equivalent toif x then y else ()).