diff options
author | 2015-06-27 22:23:41 +0200 | |
---|---|---|
committer | 2016-06-27 12:45:41 +0200 | |
commit | 5a212ff444e9e231f5b56629e5cf15087bac69c6 (patch) | |
tree | 2ad44a284c1e45dbc7a4f29075b94c2a53615a8b /interp | |
parent | 56a7d450fb67268d121e69a5e111968d0dfb2a6a (diff) |
minor: in constrintern.ml:sort_fields, clarify sf
The internal `add_pat` function is replaced by a call to
`CList.extract_first`.
Diffstat (limited to 'interp')
-rw-r--r-- | interp/constrintern.ml | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/interp/constrintern.ml b/interp/constrintern.ml index 3bd03aecc..49758f4d5 100644 --- a/interp/constrintern.ml +++ b/interp/constrintern.ml @@ -1098,30 +1098,27 @@ let sort_fields ~complete loc l completer = in (* now we want to have all fields of the pattern indexed by their place in the constructor *) - let rec sf patts accpatt = - match patts with - | [] -> accpatt - | p::q-> - let refer, patt = p in - let glob_refer = try global_reference_of_reference refer + let rec index_fields fields remaining_projs acc = + match fields with + | [] -> acc + | (field_ref, field_value) :: fields -> + let field_glob_ref = try global_reference_of_reference field_ref with |Not_found -> - user_err_loc (loc_of_reference refer, "intern", - str "The field \"" ++ pr_reference refer ++ str "\" does not exist.") in - let rec add_patt l acc = - match l with - | [] -> - user_err_loc - (loc, "", - str "This record contains fields of different records.") - | (i, a) :: b-> - if eq_gr glob_refer a - then (i,List.rev_append acc l) - else add_patt b ((i,a)::acc) - in - let (index, projs) = add_patt (snd accpatt) [] in - sf q ((index, patt)::fst accpatt, projs) in - let (unsorted_indexed_pattern, remainings) = - sf other_fields ([first_field_index, first_field_value], proj_list) in + user_err_loc (loc_of_reference field_ref, "intern", + str "The field \"" ++ pr_reference field_ref ++ str "\" does not exist.") in + let remaining_projs, (field_index, _) = + let the_proj (idx, glob_ref) = eq_gr field_glob_ref glob_ref in + try CList.extract_first the_proj remaining_projs + with Not_found -> + user_err_loc + (loc, "", + str "This record contains fields of different records.") + in + index_fields fields remaining_projs ((field_index, field_value) :: acc) + in + let unsorted_indexed_pattern = + index_fields other_fields proj_list + [(first_field_index, first_field_value)] in (* we sort them *) let sorted_indexed_pattern = let cmp_by_index (i, _) (j, _) = Int.compare i j in |