Open geohuz opened 1 month ago
Hi @geohuz, thanks for your careful reading and feedback; this is helpful.
Passing the comparison function as a higher-order parameter, as done in Array.sort, for example, would add a lot of boilerplate code.
Yes, this sentence isn't great.
I couldn't image how the higher order function way can "add a lot of boilerplate code", as a new ocaml user this can be confusing.
You are right.
I'm not sure if I understand it correctly, but I guess this should be one of the rational of using functor instead of higher order function.
Yes, you got it right. This is what a functor allows, not having to pass the comparison function (for instance) at each function call.
“Boilerplate” isn't a great term, but client code is somehow simpler/shorter as the comparison function isn't passed at each call to a functor-hosted function.
And yes, this is one of the main rationales for using functors.
Do you have suggestions on how to improve this text?
Hi @cuihtlauac, thanks for your prompt reply! My suggestion is to give an example to explain the idea, so this can happen in other functors like Set...
Do you want to propose a PR with with? It would be easier to discuss the matter with the actual example. An we love contributions :-)
In the ocaml docmentation chapter functor, when I read this paragraph:
I couldn't image how the higher order function way can "add a lot of boilerplate code", as a new ocaml user this can be confusing. I've tried to look at source code like Map module, I found a funcion that calling compare like add:
So for this case, the
add
function if without functor, then we have to define it like this:I'm not sure if I understand it correctly, but I guess this should be one of the rational of using functor instead of higher order function. I wish this can be elaborated in a crystal clear way because that is the point of having functor in Ocaml?