In OCaml, why is there an auxiliary function in Core's List.find? -
In the core, For example: what In this case, there is an advantage in using a helpful function to define a function like It does not change a lot because both functions are tail-recursive, but still, the answer to your question is: Calling This is a trade-off: in the core version, one must be allocated to share the permanent value name (code) Actually, you should not worry about it. It is probably unnecessary in this case, and even when it is not unnecessary, it does not make a big difference. List.find is defined using an auxiliary function, just like That's the following:
Let's find l ~ f = REC find_x = function | [] - & gt; None. | HD :: TL - & gt; If FHD is available in some HD / Other Finder_exto then it can be defined directly
R Rick Mill l ~ f = Match with L | [] - & gt; None. | HD :: TL - & gt; If FHD then get some HD and TL
list.find ?
Find Two arguments need to be passed Calling
find_aux is required to pass an argument Passing logic is not free: they stack Take the position, limit the maximum recursive depth if the function is not tail-recursive, and they take time to set up.
f to stop it. If the list is low, the allocation for closure can be more expensive than passing through some extra arguments (after adjectives are tail-recursive).
Comments
Post a Comment