]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/acic_procedural/procedural2.ml
- procedural: basic support for lapply (solves a problem in the reconstruction of...
[helm.git] / helm / software / components / acic_procedural / procedural2.ml
index 07c1da5f091c312f4c9518d5105cdb5e65cb6156..ff8f864eabb31320e8af90737ae1501be4085434 100644 (file)
@@ -211,24 +211,28 @@ let are_convertible st pred sx dx =
 
 let anonymous_premise = C.Name "UNNAMED"
 
-let mk_exp_args hd tl classes synth qs =
+let mk_lapply_args hd tl classes = 
+   let map _ = Cn.meta "" in
+   let args = List.rev_map map tl in
+   if args = [] then hd else C.AAppl ("", hd :: args)
+
+let mk_apply_args hd tl classes synth qs =
    let exp = ref 0 in
-   let meta id = C.AImplicit (id, None) in
    let map v (cl, b) =
       if I.overlaps synth cl
-         then if b then v, v else meta "", v
-         else meta "", meta ""
+         then if b then v, v else Cn.meta "", v
+         else Cn.meta "", Cn.meta ""
    in
    let rec rev a = function
       | []       -> a
       | hd :: tl -> 
-         if snd hd <> meta "" then incr exp;
+         if snd hd <> Cn.meta "" then incr exp;
          rev (snd hd :: a) tl 
    in
    let rec aux = function
       | []       -> []
       | hd :: tl -> 
-         if fst hd = meta "" then aux tl else rev [] (hd :: tl)
+         if fst hd = Cn.meta "" then aux tl else rev [] (hd :: tl)
    in
    let args = T.list_rev_map2 map tl classes in
    let args = aux args in
@@ -359,6 +363,26 @@ and proc_letin st what name v w t =
                  mk_fwd_rewrite st dtext intro tl true v t ity ety
               | C.AAppl (_, hd :: tl) when is_fwd_rewrite_left st hd tl  ->
                  mk_fwd_rewrite st dtext intro tl false v t ity ety
+              | C.AAppl (_, hd :: tl)                                    ->
+                  let ty = match get_inner_types st hd with
+                     | Some (ity, _) -> H.cic ity 
+                    | None          -> get_type "TC3" st hd 
+                  in
+                 let classes, _ = Cl.classify st.context ty in
+                  let parsno, argsno = List.length classes, List.length tl in
+                  let decurry = parsno - argsno in
+                 if decurry <> 0 then begin              
+(* FG: we fall back in the cut case *)              
+                    assert (Ut.is_sober st.context (H.cic ety));
+                    let ety = H.acic_bc st.context ety in
+                    let qs = [proc_proof (next st) v; [T.Id ""]] in
+                    st, [T.Branch (qs, ""); T.Cut (intro, ety, dtext)]
+                 end else
+                 let names, synth = get_sub_names hd tl, I.S.empty in
+                 let qs = proc_bkd_proofs (next st) synth names classes tl in
+                  let hd = mk_lapply_args hd tl classes in
+                 let qs = [T.Id ""] :: qs in
+                 st, [T.Branch (qs, ""); T.LApply (intro, hd, dtext)]
               | v                                                        ->
                  assert (Ut.is_sober st.context (H.cic ety));
                  let ety = H.acic_bc st.context ety in
@@ -439,7 +463,7 @@ and proc_appl st what hd tl =
            in
            if List.length qs <> List.length names then
               let qs = proc_bkd_proofs (next st) synth [] classes tl in
-              let b, hd, qs = mk_exp_args hd tl classes synth qs in
+              let b, hd, qs = mk_apply_args hd tl classes synth qs in
               script @ [tactic b hd (dtext ^ text); T.Branch (qs, "")]
            else if is_rewrite_right st hd then 
               script2 @ mk_rewrite st dtext where qs tl2 false what ity
@@ -454,7 +478,7 @@ and proc_appl st what hd tl =
         | _                                       ->
            let names = get_sub_names hd tl in
            let qs = proc_bkd_proofs (next st) synth names classes tl in
-           let b, hd, qs = mk_exp_args hd tl classes synth qs in
+           let b, hd, qs = mk_apply_args hd tl classes synth qs in
            script @ [tactic b hd (dtext ^ text); T.Branch (qs, "")]
    else
       [T.Exact (what, dtext)]