Refactoring.

This commit is contained in:
Léonard Gérard 2010-12-14 18:31:09 +01:00
parent 7d3b6a4679
commit ac9f805446
3 changed files with 9 additions and 9 deletions

View file

@ -753,7 +753,7 @@ and typing_iterator const_env h
| Ifold ->
let args_ty_list =
incomplete_map (fun ty -> Tarray (ty, n)) args_ty_list in
map_butlast (fun ty -> Tarray (ty, n)) args_ty_list in
let typed_e_list =
typing_args const_env h args_ty_list e_list in
(*check accumulator type matches in input and output*)
@ -769,7 +769,7 @@ and typing_iterator const_env h
( try unify idx_ty (Tid Initial.pint)
with TypingError _ -> raise (TypingError (Efoldi_bad_args idx_ty)));
let args_ty_list =
incomplete_map (fun ty -> Tarray (ty, n)) (args_ty_list@[acc_ty]) in
map_butlast (fun ty -> Tarray (ty, n)) (args_ty_list@[acc_ty]) in
let typed_e_list =
typing_args const_env h args_ty_list e_list in
(*check accumulator type matches in input and output*)
@ -780,9 +780,9 @@ and typing_iterator const_env h
| Imapfold ->
let args_ty_list =
incomplete_map (fun ty -> Tarray (ty, n)) args_ty_list in
map_butlast (fun ty -> Tarray (ty, n)) args_ty_list in
let result_ty_list =
incomplete_map (fun ty -> Tarray (ty, n)) result_ty_list in
map_butlast (fun ty -> Tarray (ty, n)) result_ty_list in
let typed_e_list = typing_args const_env h
args_ty_list e_list in
(*check accumulator type matches in input and output*)

View file

@ -52,11 +52,11 @@ let unique l =
List.iter (fun i -> Hashtbl.replace tbl i ()) l;
Hashtbl.fold (fun key _ accu -> key :: accu) tbl []
let rec incomplete_map f l =
let rec map_butlast f l =
match l with
| [] -> []
| [a] -> [a]
| a::l -> (f a)::(incomplete_map f l)
| a::l -> (f a)::(map_butlast f l)
let rec last_element l =
match l with

View file

@ -23,9 +23,9 @@ val reset_symbol : unit -> unit
(** [unique l] returns the [l] list without duplicates. O([length l]). *)
val unique : 'a list -> 'a list
(** [incomplete_map f l] applies f to all the elements of
l except the last element. *)
val incomplete_map : ('a -> 'a) -> 'a list -> 'a list
(** [map_butlast f l] applies f to all the elements of
l except the last element. *)
val map_butlast : ('a -> 'a) -> 'a list -> 'a list
(** [last_element l] returns the last element of the list l.*)
val last_element : 'a list -> 'a