equal
deleted
inserted
replaced
343 val add_consts = Term.fold_aterms (fn Const (c, _) => insert (op =) c | _ => I); |
343 val add_consts = Term.fold_aterms (fn Const (c, _) => insert (op =) c | _ => I); |
344 |
344 |
345 fun mapping add_names f t = |
345 fun mapping add_names f t = |
346 let |
346 let |
347 fun f' x = let val y = f x in if x = y then NONE else SOME (x, y) end; |
347 fun f' x = let val y = f x in if x = y then NONE else SOME (x, y) end; |
348 val tab = List.mapPartial f' (add_names t []); |
348 val tab = map_filter f' (add_names t []); |
349 fun get x = the_default x (AList.lookup (op =) tab x); |
349 fun get x = the_default x (AList.lookup (op =) tab x); |
350 in get end; |
350 in get end; |
351 |
351 |
352 fun typ_mapping f g thy T = |
352 fun typ_mapping f g thy T = |
353 T |> map_typ |
353 T |> map_typ |
383 (extern_term (Consts.extern_early (consts_of thy)) thy t); |
383 (extern_term (Consts.extern_early (consts_of thy)) thy t); |
384 |
384 |
385 fun pretty_typ thy T = Syntax.pretty_typ (Context.Theory thy) (syn_of thy) (extern_typ thy T); |
385 fun pretty_typ thy T = Syntax.pretty_typ (Context.Theory thy) (syn_of thy) (extern_typ thy T); |
386 fun pretty_sort thy S = Syntax.pretty_sort (Context.Theory thy) (syn_of thy) (extern_sort thy S); |
386 fun pretty_sort thy S = Syntax.pretty_sort (Context.Theory thy) (syn_of thy) (extern_sort thy S); |
387 |
387 |
388 fun pretty_classrel thy cs = Pretty.block (List.concat |
388 fun pretty_classrel thy cs = Pretty.block (flat |
389 (separate [Pretty.str " <", Pretty.brk 1] (map (single o pretty_sort thy o single) cs))); |
389 (separate [Pretty.str " <", Pretty.brk 1] (map (single o pretty_sort thy o single) cs))); |
390 |
390 |
391 fun pretty_arity thy (a, Ss, S) = |
391 fun pretty_arity thy (a, Ss, S) = |
392 let |
392 let |
393 val a' = extern_type thy a; |
393 val a' = extern_type thy a; |
595 (try (Consts.constraint consts)) def_type def_sort (Consts.intern consts) |
595 (try (Consts.constraint consts)) def_type def_sort (Consts.intern consts) |
596 (intern_tycons thy) (intern_sort thy) used freeze typs ts) |
596 (intern_tycons thy) (intern_sort thy) used freeze typs ts) |
597 handle TYPE (msg, _, _) => Exn (ERROR msg); |
597 handle TYPE (msg, _, _) => Exn (ERROR msg); |
598 |
598 |
599 val err_results = map infer termss; |
599 val err_results = map infer termss; |
600 val errs = List.mapPartial (fn Exn (ERROR msg) => SOME msg | _ => NONE) err_results; |
600 val errs = map_filter (fn Exn (ERROR msg) => SOME msg | _ => NONE) err_results; |
601 val results = List.mapPartial get_result err_results; |
601 val results = map_filter get_result err_results; |
602 |
602 |
603 val ambiguity = length termss; |
603 val ambiguity = length termss; |
604 fun ambig_msg () = |
604 fun ambig_msg () = |
605 if ambiguity > 1 andalso ambiguity <= ! Syntax.ambiguity_level then |
605 if ambiguity > 1 andalso ambiguity <= ! Syntax.ambiguity_level then |
606 "Got more than one parse tree.\n\ |
606 "Got more than one parse tree.\n\ |
612 (if ambiguity > ! Syntax.ambiguity_level then |
612 (if ambiguity > ! Syntax.ambiguity_level then |
613 warning "Fortunately, only one parse tree is type correct.\n\ |
613 warning "Fortunately, only one parse tree is type correct.\n\ |
614 \You may still want to disambiguate your grammar or your input." |
614 \You may still want to disambiguate your grammar or your input." |
615 else (); hd results) |
615 else (); hd results) |
616 else (cat_error (ambig_msg ()) ("More than one term is type correct:\n" ^ |
616 else (cat_error (ambig_msg ()) ("More than one term is type correct:\n" ^ |
617 cat_lines (map (Pretty.string_of_term pp) (List.concat (map fst results))))) |
617 cat_lines (map (Pretty.string_of_term pp) (maps fst results)))) |
618 end; |
618 end; |
619 |
619 |
620 fun infer_types pp thy consts def_type def_sort used freeze tsT = |
620 fun infer_types pp thy consts def_type def_sort used freeze tsT = |
621 apfst hd (infer_types_simult pp thy consts def_type def_sort used freeze [tsT]); |
621 apfst hd (infer_types_simult pp thy consts def_type def_sort used freeze [tsT]); |
622 |
622 |