X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=ocaml%2Fnum.ml;h=eb37e4ca41d0c1b2b6f27f6ddf24edadacaba842;hb=588a00cd5ae861a2f366df992f758f285265a34a;hp=2cb9b731a1dda17d50f9211a694548e7153b89bf;hpb=0e005c102417c907b7dd0ec48a45739fafe54f59;p=fireball-separation.git diff --git a/ocaml/num.ml b/ocaml/num.ml index 2cb9b73..eb37e4c 100644 --- a/ocaml/num.ml +++ b/ocaml/num.ml @@ -70,12 +70,12 @@ let rec make_lams t = | n when n > 0 -> `Lam (false, lift 1 (make_lams t (n-1))) | _ -> assert false -let free_vars = +let free_vars' = let rec aux n = function `N _ -> [] - | `Var(x,_) -> if x < n then [] else [x-n] - | `I((x,_),args) -> - (if x < n then [] else [x-n]) @ + | `Var(x,ar) -> if x < n then [] else [(x-n,ar)] + | `I((x,ar),args) -> + (if x < n then [] else [(x-n,ar)]) @ List.concat (List.map (aux n) (Listx.to_list args)) | `Lam(_,t) -> aux (n+1) t | `Match(t,_,liftno,bs,args) -> @@ -84,6 +84,7 @@ let free_vars = List.concat (List.map (aux n) args) in aux 0 ;; +let free_vars = (List.map fst) ++ free_vars';; module ToScott = struct @@ -114,8 +115,8 @@ let rec string_of_term l = | `N n -> string_of_int n | `I _ as t -> "(" ^ string_of_term_no_pars_app l (t :> nf) ^ ")" | `Lam _ as t -> "(" ^ string_of_term_no_pars_lam l t ^ ")" - | `Match(t,_,bs_lift,bs,args) -> - "(match " ^ string_of_term_no_pars l (t :> nf) ^ + | `Match(t,(v,ar),bs_lift,bs,args) -> + "[match("^ string_of_var v ^":"^ string_of_int ar ^") " ^ string_of_term_no_pars l (t :> nf) ^ " with " ^ String.concat " | " (List.map (fun (n,t) -> string_of_int n ^ " => " ^ string_of_term l (lift bs_lift t)) !bs) ^ "] " ^ String.concat " " (List.map (string_of_term l) args) ^ ")" and string_of_term_no_pars_app l = function @@ -157,12 +158,12 @@ let cast_to_i_num_var = prerr_endline (print (t :> nf)); assert false (* algorithm failed *) -let set_arity arity = function +let rec set_arity arity = function | `Var(n,_) -> `Var(n,arity) -| `Lam(false, `N _) -| `Lam(false, `Lam _) as t -> t -| `Lam(false, `Match(t,(n,_),bs_lift,bs,args)) -> `Lam(false, `Match(t,(n,arity),bs_lift,bs,args)) -| _ -> assert false +| `N _ as t -> t +| `Lam(false, t) -> `Lam(false, set_arity arity t) +| `Match(t,(n,_),bs_lift,bs,args) -> `Match(t,(n,arity),bs_lift,bs,args) +| `I _ | `Lam _ -> assert false let minus1 n = if n = min_int then n else n - 1;; @@ -197,10 +198,11 @@ and mk_match t (n,ar) bs_lift bs args = | `I _ | `Var _ | `Match _ -> `Match(t,(n,ar),bs_lift,bs,args) and subst truelam delift_by_one what (with_what : nf) (where : nf) = - let aux_propagate_arity ar = function - | `Lam(false,`Match(`I(v,args),(x,_),liftno,bs,args')) when not delift_by_one -> - `Lam(false,`Match(`I(v,args),(x,ar),liftno,bs,args')) - | `Var(i,oldar) -> `Var(i, if truelam && oldar = min_int then ar else oldar) + let rec aux_propagate_arity ar = function + | `Lam(false, t) when not delift_by_one -> `Lam(false, aux_propagate_arity ar t) + | `Match(`I(v,args),(x,_),liftno,bs,args') when not delift_by_one -> + `Match(`I(v,args),(x,ar),liftno,bs,args') + | `Var(i,oldar) -> `Var(i, if truelam then (assert (oldar = min_int); ar) else oldar) | _ as t -> t in let rec aux_i_num_var l = function