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