src/Pure/Syntax/syntax_trans.ML
changeset 81543 fa37ee54644c
parent 81516 31b05aef022d
child 81544 dfd5f665db69
equal deleted inserted replaced
81542:e2ab4147b244 81543:fa37ee54644c
   300 
   300 
   301 fun mark_bound_abs (x, T) = Const ("_bound", T --> T) $ Free (x, T);
   301 fun mark_bound_abs (x, T) = Const ("_bound", T --> T) $ Free (x, T);
   302 fun mark_bound_body (x, T) = Const ("_bound", dummyT) $ Free (x, T);
   302 fun mark_bound_body (x, T) = Const ("_bound", dummyT) $ Free (x, T);
   303 
   303 
   304 fun bound_vars vars body =
   304 fun bound_vars vars body =
   305   subst_bounds (map mark_bound_abs (rev (Term.variant_frees body vars)), body);
   305   subst_bounds (map mark_bound_abs (rev (Term.variant_bounds body vars)), body);
   306 
   306 
   307 fun strip_abss vars_of body_of tm =
   307 fun strip_abss vars_of body_of tm =
   308   let
   308   let
   309     val vars = vars_of tm;
   309     val vars = vars_of tm;
   310     val body = body_of tm;
   310     val body = body_of tm;
   311     val new_vars = Term.variant_frees body vars;
   311     val new_vars = Term.variant_bounds body vars;
   312     fun subst (x, T) b =
   312     fun subst (x, T) b =
   313       if Name.is_internal x andalso not (Term.is_dependent b)
   313       if Name.is_internal x andalso not (Term.is_dependent b)
   314       then (Const ("_idtdummy", T), incr_boundvars ~1 b)
   314       then (Const ("_idtdummy", T), incr_boundvars ~1 b)
   315       else (mark_bound_abs (x, T), Term.subst_bound (mark_bound_body (x, T), b));
   315       else (mark_bound_abs (x, T), Term.subst_bound (mark_bound_body (x, T), b));
   316     val (rev_vars', body') = fold_map subst (rev new_vars) body;
   316     val (rev_vars', body') = fold_map subst (rev new_vars) body;
   320 fun abs_tr' ctxt tm =
   320 fun abs_tr' ctxt tm =
   321   uncurry (fold_rev (fn x => fn t => Syntax.const "_abs" $ x $ t))
   321   uncurry (fold_rev (fn x => fn t => Syntax.const "_abs" $ x $ t))
   322     (strip_abss strip_abs_vars strip_abs_body (eta_contr ctxt tm));
   322     (strip_abss strip_abs_vars strip_abs_body (eta_contr ctxt tm));
   323 
   323 
   324 fun atomic_abs_tr' (x, T, t) =
   324 fun atomic_abs_tr' (x, T, t) =
   325   let val xT = singleton (Term.variant_frees t) (x, T)
   325   let val xT = singleton (Term.variant_bounds t) (x, T)
   326   in (mark_bound_abs xT, subst_bound (mark_bound_body xT, t)) end;
   326   in (mark_bound_abs xT, subst_bound (mark_bound_body xT, t)) end;
   327 
   327 
   328 fun abs_ast_tr' asts =
   328 fun abs_ast_tr' asts =
   329   (case Ast.unfold_ast_p "_abs" (Ast.Appl (Ast.Constant "_abs" :: asts)) of
   329   (case Ast.unfold_ast_p "_abs" (Ast.Appl (Ast.Constant "_abs" :: asts)) of
   330     ([], _) => raise Ast.AST ("abs_ast_tr'", asts)
   330     ([], _) => raise Ast.AST ("abs_ast_tr'", asts)
   387 
   387 
   388 
   388 
   389 (* dependent / nondependent quantifiers *)
   389 (* dependent / nondependent quantifiers *)
   390 
   390 
   391 fun print_abs (x, T, b) =
   391 fun print_abs (x, T, b) =
   392   let val x' = #1 (Name.variant x (Name.build_context (Term.declare_term_names b)))
   392   let val x' = #1 (Name.variant x (Name.build_context (Term.declare_free_names b)))
   393   in (x', subst_bound (mark_bound_abs (x', T), b)) end;
   393   in (x', subst_bound (mark_bound_abs (x', T), b)) end;
   394 
   394 
   395 fun dependent_tr' (q, r) (A :: Abs (x, T, B) :: ts) =
   395 fun dependent_tr' (q, r) (A :: Abs (x, T, B) :: ts) =
   396       if Term.is_dependent B then
   396       if Term.is_dependent B then
   397         let val (x', B') = print_abs (x, dummyT, B);
   397         let val (x', B') = print_abs (x, dummyT, B);