cakeml icon indicating copy to clipboard operation
cakeml copied to clipboard

Remove accumulator-based functions from the semantics

Open charguer opened this issue 6 years ago • 2 comments

Ideally, auxiliary functions used in the semantics should have the simplest possible presentation, and not use accumulators.

E.g. pat_bindings currently has type pat -> list varN -> list varN but it should be pat > list varN. There might be a few other occurrences.

charguer avatar Jul 02 '19 13:07 charguer

Fixpoint pat_bindings (p : pat) : list varN :=
  match p with
  | Pany => []
  | Pvar n => n :: []
  | Plit l => []
  | Pcon _ ps => List.fold_right (fun p acc => acc ++ pat_bindings p) [] ps
  | Pref p => pat_bindings p
  | Ptannot p _ => pat_bindings p
  end.

charguer avatar Jul 03 '19 12:07 charguer

Another occurence is pmatch, which takes as last argument an env. I think this accumulator could be avoided, simply by making pmatch_list concatenate the list of bindings that it gathers, rather than extending the accumulator as it recurses.

charguer avatar Jul 03 '19 15:07 charguer