diff --git a/compiler/minils/transformations/normalize.ml b/compiler/minils/transformations/normalize.ml index 355afe4..33f800a 100644 --- a/compiler/minils/transformations/normalize.ml +++ b/compiler/minils/transformations/normalize.ml @@ -190,13 +190,12 @@ let rec translate kind context e = | Eiterator (it, app, n, e_list, reset) -> (* Add an intermediate equation for each array lit argument. *) let translate_iterator_arg_list context e_list = - let add e (context, e_list) = + let add e context = let kind = match e.e_desc with | Econst { se_desc = Sarray _; } -> VRef | _ -> function_args_kind in - let (context, e) = translate kind context e in - (context, e :: e_list) in - List.fold_right add e_list (context, []) in + translate kind context e in + Misc.mapfold_right add e_list context in let context, e_list = translate_iterator_arg_list context e_list in diff --git a/compiler/utilities/misc.ml b/compiler/utilities/misc.ml index a63fb59..f0546c9 100644 --- a/compiler/utilities/misc.ml +++ b/compiler/utilities/misc.ml @@ -216,6 +216,9 @@ let mapfold f acc l = ([],acc) l in List.rev l, acc +let mapfold_right f l acc = + List.fold_right (fun e (acc, l) -> let acc, e = f e acc in (acc, e :: l)) + l (acc, []) let mapi f l = let rec aux i = function diff --git a/compiler/utilities/misc.mli b/compiler/utilities/misc.mli index 5ccc16e..0161b4c 100644 --- a/compiler/utilities/misc.mli +++ b/compiler/utilities/misc.mli @@ -173,6 +173,10 @@ exception Fallback (** Mapfold *) val mapfold: ('a -> 'b -> 'c * 'a) -> 'a -> 'b list -> 'c list * 'a +(** Mapfold, right version. *) +val mapfold_right + : ('a -> 'acc -> 'acc * 'b) -> 'a list -> 'acc -> 'acc * 'b list + (** Mapi *) val mapi: (int -> 'a -> 'b) -> 'a list -> 'b list val mapi2: (int -> 'a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list