Im Kern ist List.find
unter Verwendung einer Hilfsfunktion definiert ist, wie folgt: kannWarum gibt es in OCaml eine Hilfsfunktion in List.find?
let find l ~f =
let rec find_aux = function
| [] -> None
| hd :: tl -> if f hd then Some hd else find_aux tl
in
find_aux l
Aber es direkt festgelegt werden. Zum Beispiel:
let rec find l ~f =
match l with
| [] -> None
| hd :: tl -> if f hd then Some hd else find tl f
Gibt es einen Vorteil in eine Hilfsfunktion mit einer Funktion wie List.find
für die Definition?
In Haskell sind die zusätzlichen inlining Möglichkeiten, die Sie bekommen, indem Sie so etwas tun, eine große Sache. Ich weiß nicht, ob OCaml das gleiche ist. Suchbegriffe: statische Argumentumwandlung, Worker-Wrapper-Transformation –