In OCaml, why is there an auxiliary function in Core's List.find? -


In the core, 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   

For example:

  R Rick Mill l ~ f = Match with L | [] - & gt; None. | HD :: TL - & gt; If FHD then get some HD and TL   

what list.find ?

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 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.

This is a trade-off: in the core version, one must be allocated to share the permanent value name (code) 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).

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.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -