TMC optimize List.flat_map
This commit is contained in:
parent
7d4fa61935
commit
2d9aaff4ef
|
@ -20,11 +20,16 @@ module List = struct
|
|||
include List
|
||||
|
||||
let flat_map f xs =
|
||||
let rec iter acc = function
|
||||
| [] -> rev acc
|
||||
| x :: xs -> iter (rev_append (f x) acc) xs
|
||||
let rec iter = function
|
||||
| [] -> []
|
||||
| x :: xs -> append_then_iter xs (f x)
|
||||
[@@tail_mod_cons]
|
||||
and append_then_iter xs = function
|
||||
| [] -> iter xs
|
||||
| y :: ys -> y :: append_then_iter xs ys
|
||||
[@@tail_mod_cons]
|
||||
in
|
||||
iter [] xs
|
||||
iter xs
|
||||
end
|
||||
|
||||
include (val Logging.logs "Irc")
|
||||
|
|
Loading…
Reference in New Issue