src/Pure/Syntax/syntax_trans.ML
changeset 81516 31b05aef022d
parent 81506 f76a5849b570
child 81543 fa37ee54644c
equal deleted inserted replaced
81515:44c0028486db 81516:31b05aef022d
   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 (Term.rename_wrt_term body vars), body);
   305   subst_bounds (map mark_bound_abs (rev (Term.variant_frees 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 rev_new_vars = Term.rename_wrt_term body vars;
   311     val new_vars = Term.variant_frees 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;
   317   in (rev rev_vars', body') end;
   317   in (rev rev_vars', body') end;
   318 
   318 
   319 
   319 
   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] = Term.rename_wrt_term t [(x, T)]
   325   let val xT = singleton (Term.variant_frees 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)