42 else cannot_merge_types (); |
42 else cannot_merge_types (); |
43 |
43 |
44 fun type_args_constrained_of (((cAs, _), _), _) = cAs; |
44 fun type_args_constrained_of (((cAs, _), _), _) = cAs; |
45 val type_args_of = map fst o type_args_constrained_of; |
45 val type_args_of = map fst o type_args_constrained_of; |
46 fun type_binder_of (((_, b), _), _) = b; |
46 fun type_binder_of (((_, b), _), _) = b; |
47 fun mixfix_of_typ ((_, mx), _) = mx; |
47 fun mixfix_of ((_, mx), _) = mx; |
48 fun ctr_specs_of (_, ctr_specs) = ctr_specs; |
48 fun ctr_specs_of (_, ctr_specs) = ctr_specs; |
49 |
49 |
50 fun disc_of (((disc, _), _), _) = disc; |
50 fun disc_of (((disc, _), _), _) = disc; |
51 fun ctr_of (((_, ctr), _), _) = ctr; |
51 fun ctr_of (((_, ctr), _), _) = ctr; |
52 fun args_of ((_, args), _) = args; |
52 fun args_of ((_, args), _) = args; |
53 fun mixfix_of_ctr (_, mx) = mx; |
53 fun ctr_mixfix_of (_, mx) = mx; |
54 |
54 |
55 fun prepare_data prepare_typ gfp specs fake_lthy lthy = |
55 fun prepare_data prepare_typ gfp specs fake_lthy lthy = |
56 let |
56 let |
57 val constrained_As = |
57 val constrained_As = |
58 map (map (apfst (prepare_typ fake_lthy)) o type_args_constrained_of) specs |
58 map (map (apfst (prepare_typ fake_lthy)) o type_args_constrained_of) specs |
72 As); |
72 As); |
73 |
73 |
74 val bs = map type_binder_of specs; |
74 val bs = map type_binder_of specs; |
75 val fp_Ts = map mk_T bs; |
75 val fp_Ts = map mk_T bs; |
76 |
76 |
77 val mixfixes = map mixfix_of_typ specs; |
77 val mixfixes = map mixfix_of specs; |
78 |
78 |
79 val _ = (case duplicates Binding.eq_name bs of [] => () |
79 val _ = (case duplicates Binding.eq_name bs of [] => () |
80 | b :: _ => error ("Duplicate type name declaration " ^ quote (Binding.name_of b))); |
80 | b :: _ => error ("Duplicate type name declaration " ^ quote (Binding.name_of b))); |
81 |
81 |
82 val ctr_specss = map ctr_specs_of specs; |
82 val ctr_specss = map ctr_specs_of specs; |
83 |
83 |
84 val disc_binderss = map (map disc_of) ctr_specss; |
84 val disc_binderss = map (map disc_of) ctr_specss; |
85 val ctr_binderss = map (map ctr_of) ctr_specss; |
85 val ctr_binderss = map (map ctr_of) ctr_specss; |
86 val ctr_argsss = map (map args_of) ctr_specss; |
86 val ctr_argsss = map (map args_of) ctr_specss; |
87 val ctr_mixfixess = map (map mixfix_of_ctr) ctr_specss; |
87 val ctr_mixfixess = map (map ctr_mixfix_of) ctr_specss; |
88 |
88 |
89 val sel_bindersss = map (map (map fst)) ctr_argsss; |
89 val sel_bindersss = map (map (map fst)) ctr_argsss; |
90 val ctr_Tsss = map (map (map (prepare_typ fake_lthy o snd))) ctr_argsss; |
90 val ctr_Tsss = map (map (map (prepare_typ fake_lthy o snd))) ctr_argsss; |
91 |
91 |
92 val rhs_As' = fold (fold (fold Term.add_tfreesT)) ctr_Tsss []; |
92 val rhs_As' = fold (fold (fold Term.add_tfreesT)) ctr_Tsss []; |
276 |
276 |
277 fun data_cmd info specs lthy = |
277 fun data_cmd info specs lthy = |
278 let |
278 let |
279 val fake_thy = Theory.copy |
279 val fake_thy = Theory.copy |
280 #> fold (fn spec => Sign.add_type lthy |
280 #> fold (fn spec => Sign.add_type lthy |
281 (type_binder_of spec, length (type_args_constrained_of spec), mixfix_of_typ spec)) specs; |
281 (type_binder_of spec, length (type_args_constrained_of spec), mixfix_of spec)) specs; |
282 val fake_lthy = Proof_Context.background_theory fake_thy lthy; |
282 val fake_lthy = Proof_Context.background_theory fake_thy lthy; |
283 in |
283 in |
284 prepare_data Syntax.read_typ info specs fake_lthy lthy |
284 prepare_data Syntax.read_typ info specs fake_lthy lthy |
285 end; |
285 end; |
286 |
286 |