355 val parm_types' = parm_types |
355 val parm_types' = parm_types |
356 |> map (Type_Infer.paramify_vars o |
356 |> map (Type_Infer.paramify_vars o |
357 Term.map_type_tvar (fn ((x, _), S) => TVar ((x, i), S)) o Logic.varifyT_global); |
357 Term.map_type_tvar (fn ((x, _), S) => TVar ((x, i), S)) o Logic.varifyT_global); |
358 val inst'' = map2 Type.constraint parm_types' inst'; |
358 val inst'' = map2 Type.constraint parm_types' inst'; |
359 val insts' = insts @ [(loc, (prfx, inst''))]; |
359 val insts' = insts @ [(loc, (prfx, inst''))]; |
360 val (insts'', _, _, ctxt' (* FIXME not used *) ) = check_autofix insts' [] [] ctxt; |
360 val (insts'', _, _, _) = check_autofix insts' [] [] ctxt; |
361 val inst''' = insts'' |> List.last |> snd |> snd; |
361 val inst''' = insts'' |> List.last |> snd |> snd; |
362 val (morph, _) = inst_morph (parm_names, parm_types) (prfx, inst''') ctxt; |
362 val (morph, _) = inst_morph (parm_names, parm_types) (prfx, inst''') ctxt; |
363 val ctxt'' = Locale.activate_declarations (loc, morph) ctxt; |
363 val ctxt'' = Locale.activate_declarations (loc, morph) ctxt; |
364 in (i + 1, insts', ctxt'') end; |
364 in (i + 1, insts', ctxt'') end; |
365 |
365 |
366 fun prep_elem insts raw_elem (elems, ctxt) = |
366 fun prep_elem insts raw_elem ctxt = |
367 let |
367 let |
368 val ctxt' = declare_elem prep_vars_elem raw_elem ctxt; |
368 val ctxt' = ctxt |
369 val elems' = elems @ [parse_elem parse_typ parse_prop ctxt' raw_elem]; |
369 |> Context_Position.set_visible false |
370 val (_, _, _, ctxt'' (* FIXME not used *) ) = check_autofix insts elems' [] ctxt'; |
370 |> declare_elem prep_vars_elem raw_elem |
|
371 |> Context_Position.restore_visible ctxt; |
|
372 val elems' = parse_elem parse_typ parse_prop ctxt' raw_elem; |
371 in (elems', ctxt') end; |
373 in (elems', ctxt') end; |
372 |
374 |
373 fun prep_concl raw_concl (insts, elems, ctxt) = |
375 fun prep_concl raw_concl (insts, elems, ctxt) = |
374 let |
376 let |
375 val concl = parse_concl parse_prop ctxt raw_concl; |
377 val concl = parse_concl parse_prop ctxt raw_concl; |
386 [] => () |
388 [] => () |
387 | frees => error ("Illegal free variables in expression: " ^ |
389 | frees => error ("Illegal free variables in expression: " ^ |
388 commas_quote (map (Syntax.string_of_term ctxt3 o Free) (rev frees)))); |
390 commas_quote (map (Syntax.string_of_term ctxt3 o Free) (rev frees)))); |
389 |
391 |
390 val ctxt4 = init_body ctxt3; |
392 val ctxt4 = init_body ctxt3; |
391 val (elems, ctxt5) = fold (prep_elem insts') raw_elems ([], ctxt4); |
393 val (elems, ctxt5) = fold_map (prep_elem insts') raw_elems ctxt4; |
392 val (insts, elems', concl, ctxt6) = prep_concl raw_concl (insts', elems, ctxt5); |
394 val (insts, elems', concl, ctxt6) = prep_concl raw_concl (insts', elems, ctxt5); |
393 |
395 |
394 (* Retrieve parameter types *) |
396 (* Retrieve parameter types *) |
395 val xs = fold (fn Fixes fixes => (fn ps => ps @ map (Variable.check_name o #1) fixes) |
397 val xs = fold (fn Fixes fixes => (fn ps => ps @ map (Variable.check_name o #1) fixes) |
396 | _ => fn ps => ps) (Fixes fors :: elems') []; |
398 | _ => fn ps => ps) (Fixes fors :: elems') []; |