Skip to content

Commit 4370fa1

Browse files
authored
flambda-backend: Review changes of term directory (#602)
1 parent 65a4566 commit 4370fa1

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

utils/misc.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ module Stdlib = struct
148148
in
149149
aux n [] l
150150

151+
let rec map_sharing f l0 =
152+
match l0 with
153+
| a :: l ->
154+
let a' = f a in
155+
let l' = map_sharing f l in
156+
if a' == a && l' == l then l0 else a' :: l'
157+
| [] -> []
158+
151159
let rec is_prefix ~equal t ~of_ =
152160
match t, of_ with
153161
| [], [] -> true

utils/misc.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ module Stdlib : sig
116116
the [n] first elements of [l] and [after] the remaining ones.
117117
If [l] has less than [n] elements, raises Invalid_argument. *)
118118

119+
val map_sharing : ('a -> 'a) -> 'a t -> 'a t
120+
(** [map_sharing f l] is [map f l]. If for all elements of the list
121+
[f e == e] then [map_sharing f l == l] *)
122+
119123
val is_prefix
120124
: equal:('a -> 'a -> bool)
121125
-> 'a list

0 commit comments

Comments
 (0)