Mapfold_right for even nicer code.
This commit is contained in:
parent
496919ff63
commit
4edc03c163
3 changed files with 10 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue