Every time I write something of the form
let scorePopulation f population =
Array.map (fun i -> f i) population
I end up asking myself if wouldn't I be better writing
let scorePopulation f =
Array.map (fun i -> f i)
instead. Is there any advantage of writing it in the first form as opposed to the second?
Also, how would you call a function definition in the first form and in the second form?
You could go even further:
let scorePopulation = Array.map
In terms of advantages/disadvantages, I think that the main concern will typically be readability. Sometimes it's easier to understand what a function does when all of the arguments are present. Other times, the fact that you don't need to make up extraneous variable names wins out.
Actually, the pros and cons are the same: naming.
The reason for this is the old saying by Phil Karlton:
There are only two hard problems in computer science. Cache invalidation and naming things.
If naming things is hard (i.e. expensive), then names shouldn't be wasted on irrelevant things. And conversely, if something has a name, then it is important.
Point-free style allows you to omit names.
The pro is that it allows you to omit irrelevant names.
The con is that it allows you to omit relevant names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With