This issue came up in an erratum from the book I’m writing:
This is the kind of annotation I see in most code:
let avg1 = (a: float, b: float): float =>
(a +. b) /. 2.0;
It is also possible to annotate in the same way you would in an .rei
file:
let avg2: (float, float) => float
= (a, b) => (a +. b) /. 2.0;
The person who filled the suggestion said, “…the second version does not conflate the notion of the function’s TYPE with the parameter names that are being used to support the IMPLEMENTATION (separation of concerns). … it is also the type that is reported in rtop
when one defines the function…Interestingly enough at this time refmt
doesn’t seem to have an opinion on the style of annotations to prefer as it simply leaves them alone.”
I am curious to know why the first method seems to be preferred, especially since the second method encourages consistency.