Let me begin by stating that F# automatically generalizes (https://msdn.microsoft.com/visualfsharpdocs/conceptual/automatic-generalization-%5bfsharp%5d) arguments of functions where it is possible to deal with the multiplicity of types.
So far, we have mostly been dealing with the generalization of data collections. That is, a sequence is agnostic to the type of its elements. That's why we were able to write functions that operate on sequences of arbitrary generic type. And F# type inference spots and carries this property on.
Suppose that we proudly implement our own function of reversing a list as follows (Ch10_1.fsx
):
let reverse ls = let rec rev acc = function | h::t -> rev (h::acc) t | [] -> acc rev [] ls
Then, we may notice that the F# compiler infers the reverse : ls:'a list -> 'alist
signature for it, where 'a
indicates that the function can be applied to any type of list elements. And if we decide to check...