ocaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Reformat Suggestions.ml

+13 -21
+13 -21
lib/compiler/Suggestions.ml
··· 4 4 * SPDX-License-Identifier: GPL-3.0-or-later OR Apache-2.0 WITH LLVM-exception 5 5 * 6 6 *) 7 - open Forester_core 7 + 8 + open Forester_prelude 9 + open Forester_core 8 10 open Bwd 9 11 10 12 (* TODO: remove this in favor of https://github.com/ocaml/ocaml/pull/13760 *) ··· 12 14 let len_x, len_y = String.length x, String.length y in 13 15 let grid = Array.make_matrix (len_x + 1) (len_y + 1) 0 in 14 16 for i = 1 to len_x do 15 - grid.(i).(0) <- i; 17 + grid.(i).(0) <- i 16 18 done; 17 19 for j = 1 to len_y do 18 - grid.(0).(j) <- j; 20 + grid.(0).(j) <- j 19 21 done; 20 22 for j = 1 to len_y do 21 23 for i = 1 to len_x do ··· 29 31 else 30 32 Some result 31 33 32 - let suggestions 33 - ?prefix 34 - ~(cutoff : int) 35 - (p : Trie.bwd_path) 36 - : ('data, 'tag) Trie.t -> ('data, int) Trie.t 37 - = 34 + let suggestions ?prefix ~(cutoff : int) (p : Trie.bwd_path) : ('data, 'tag) Trie.t -> ('data, int) Trie.t = 38 35 let compare p d = 39 - edit_distance ~cutoff (String.concat "" (Bwd.to_list p)) (String.concat "" (Bwd.to_list d)) 36 + edit_distance 37 + ~cutoff 38 + (String.concat "" (Bwd.to_list p)) 39 + (String.concat "" (Bwd.to_list d)) 40 40 in 41 - Trie.filter_map 42 - ?prefix 43 - (fun q (data, _) -> 44 - match compare p q with 45 - | Some i -> 46 - if i > cutoff then 47 - None 48 - else 49 - (Some (data, i)) 50 - | None -> None 51 - ) 41 + Trie.filter_map ?prefix @@ fun q (data, _) -> 42 + let@ i = Option.bind @@ compare p q in 43 + if i > cutoff then None else Some (data, i) 52 44 53 45 let suggestions ~visible path = 54 46 suggestions ~cutoff: 2 (Bwd.of_list path) visible