402 Syntax.const "split" $ abstr (x, abstr (y, body)) |
402 Syntax.const "split" $ abstr (x, abstr (y, body)) |
403 | abstr (t, _) = case_error "Illegal pattern" NONE [t]; |
403 | abstr (t, _) = case_error "Illegal pattern" NONE [t]; |
404 in case find_first (fn (_, {descr, index, ...}) => |
404 in case find_first (fn (_, {descr, index, ...}) => |
405 exists (equal cname o fst) (#3 (snd (List.nth (descr, index))))) tab of |
405 exists (equal cname o fst) (#3 (snd (List.nth (descr, index))))) tab of |
406 NONE => case_error ("Not a datatype constructor: " ^ cname) NONE [u] |
406 NONE => case_error ("Not a datatype constructor: " ^ cname) NONE [u] |
407 | SOME (tname, {descr, case_name, index, ...}) => |
407 | SOME (tname, {descr, sorts, case_name, index, ...}) => |
408 let |
408 let |
409 val _ = if exists (equal "dummy_pattern" o fst o fst) cases' then |
409 val _ = if exists (equal "dummy_pattern" o fst o fst) cases' then |
410 case_error "Illegal occurrence of '_' dummy pattern" (SOME tname) [u] else (); |
410 case_error "Illegal occurrence of '_' dummy pattern" (SOME tname) [u] else (); |
411 val (_, (_, dts, constrs)) = List.nth (descr, index); |
411 val (_, (_, dts, constrs)) = List.nth (descr, index); |
412 val sorts = map (rpair [] o dest_DtTFree) dts; |
|
413 fun find_case (cases, (s, dt)) = |
412 fun find_case (cases, (s, dt)) = |
414 (case find_first (equal s o fst o fst) cases' of |
413 (case find_first (equal s o fst o fst) cases' of |
415 NONE => (case default of |
414 NONE => (case default of |
416 NONE => case_error ("No clause for constructor " ^ s) (SOME tname) [u] |
415 NONE => case_error ("No clause for constructor " ^ s) (SOME tname) [u] |
417 | SOME t => (cases, list_abs (map (rpair dummyT) (DatatypeProp.make_tnames |
416 | SOME t => (cases, list_abs (map (rpair dummyT) (DatatypeProp.make_tnames |
507 end; |
506 end; |
508 |
507 |
509 |
508 |
510 (**** make datatype info ****) |
509 (**** make datatype info ****) |
511 |
510 |
512 fun make_dt_info descr induct reccomb_names rec_thms |
511 fun make_dt_info descr sorts induct reccomb_names rec_thms |
513 (((((((((i, (_, (tname, _, _))), case_name), case_thms), |
512 (((((((((i, (_, (tname, _, _))), case_name), case_thms), |
514 exhaustion_thm), distinct_thm), inject), nchotomy), case_cong), weak_case_cong) = |
513 exhaustion_thm), distinct_thm), inject), nchotomy), case_cong), weak_case_cong) = |
515 (tname, |
514 (tname, |
516 {index = i, |
515 {index = i, |
517 descr = descr, |
516 descr = descr, |
|
517 sorts = sorts, |
518 rec_names = reccomb_names, |
518 rec_names = reccomb_names, |
519 rec_rewrites = rec_thms, |
519 rec_rewrites = rec_thms, |
520 case_name = case_name, |
520 case_name = case_name, |
521 case_rewrites = case_thms, |
521 case_rewrites = case_thms, |
522 induction = induct, |
522 induction = induct, |
668 val (thy10, case_congs) = add_and_get_axioms "case_cong" new_type_names |
668 val (thy10, case_congs) = add_and_get_axioms "case_cong" new_type_names |
669 (DatatypeProp.make_case_congs new_type_names descr sorts thy9) thy9; |
669 (DatatypeProp.make_case_congs new_type_names descr sorts thy9) thy9; |
670 val (thy11, weak_case_congs) = add_and_get_axioms "weak_case_cong" new_type_names |
670 val (thy11, weak_case_congs) = add_and_get_axioms "weak_case_cong" new_type_names |
671 (DatatypeProp.make_weak_case_congs new_type_names descr sorts thy10) thy10; |
671 (DatatypeProp.make_weak_case_congs new_type_names descr sorts thy10) thy10; |
672 |
672 |
673 val dt_infos = map (make_dt_info descr' induct reccomb_names' rec_thms) |
673 val dt_infos = map (make_dt_info descr' sorts induct reccomb_names' rec_thms) |
674 ((0 upto length (hd descr) - 1) ~~ (hd descr) ~~ case_names' ~~ case_thms ~~ |
674 ((0 upto length (hd descr) - 1) ~~ (hd descr) ~~ case_names' ~~ case_thms ~~ |
675 exhaustion ~~ replicate (length (hd descr)) QuickAndDirty ~~ inject ~~ |
675 exhaustion ~~ replicate (length (hd descr)) QuickAndDirty ~~ inject ~~ |
676 nchotomys ~~ case_congs ~~ weak_case_congs); |
676 nchotomys ~~ case_congs ~~ weak_case_congs); |
677 |
677 |
678 val simps = List.concat (distinct @ inject @ case_thms) @ size_thms @ rec_thms; |
678 val simps = List.concat (distinct @ inject @ case_thms) @ size_thms @ rec_thms; |
727 val (weak_case_congs, thy10) = DatatypeAbsProofs.prove_weak_case_congs new_type_names |
727 val (weak_case_congs, thy10) = DatatypeAbsProofs.prove_weak_case_congs new_type_names |
728 descr sorts thy9; |
728 descr sorts thy9; |
729 val (size_thms, thy11) = DatatypeAbsProofs.prove_size_thms flat_names new_type_names |
729 val (size_thms, thy11) = DatatypeAbsProofs.prove_size_thms flat_names new_type_names |
730 descr sorts reccomb_names rec_thms thy10; |
730 descr sorts reccomb_names rec_thms thy10; |
731 |
731 |
732 val dt_infos = map (make_dt_info (List.concat descr) induct reccomb_names rec_thms) |
732 val dt_infos = map (make_dt_info (List.concat descr) sorts induct reccomb_names rec_thms) |
733 ((0 upto length (hd descr) - 1) ~~ (hd descr) ~~ case_names ~~ case_thms ~~ |
733 ((0 upto length (hd descr) - 1) ~~ (hd descr) ~~ case_names ~~ case_thms ~~ |
734 casedist_thms ~~ simproc_dists ~~ inject ~~ nchotomys ~~ case_congs ~~ weak_case_congs); |
734 casedist_thms ~~ simproc_dists ~~ inject ~~ nchotomys ~~ case_congs ~~ weak_case_congs); |
735 |
735 |
736 val simps = List.concat (distinct @ inject @ case_thms) @ size_thms @ rec_thms; |
736 val simps = List.concat (distinct @ inject @ case_thms) @ size_thms @ rec_thms; |
737 |
737 |
835 store_thmss "inject" new_type_names inject |> snd |> |
835 store_thmss "inject" new_type_names inject |> snd |> |
836 store_thmss "distinct" new_type_names distinct |> snd |> |
836 store_thmss "distinct" new_type_names distinct |> snd |> |
837 Theory.add_path (space_implode "_" new_type_names) |> |
837 Theory.add_path (space_implode "_" new_type_names) |> |
838 PureThy.add_thms [(("induct", induction), [case_names_induct])] |> Library.swap; |
838 PureThy.add_thms [(("induct", induction), [case_names_induct])] |> Library.swap; |
839 |
839 |
840 val dt_infos = map (make_dt_info descr induction' reccomb_names rec_thms) |
840 val dt_infos = map (make_dt_info descr sorts induction' reccomb_names rec_thms) |
841 ((0 upto length descr - 1) ~~ descr ~~ case_names ~~ case_thms ~~ casedist_thms ~~ |
841 ((0 upto length descr - 1) ~~ descr ~~ case_names ~~ case_thms ~~ casedist_thms ~~ |
842 map FewConstrs distinct ~~ inject ~~ nchotomys ~~ case_congs ~~ weak_case_congs); |
842 map FewConstrs distinct ~~ inject ~~ nchotomys ~~ case_congs ~~ weak_case_congs); |
843 |
843 |
844 val simps = List.concat (distinct @ inject @ case_thms) @ size_thms @ rec_thms; |
844 val simps = List.concat (distinct @ inject @ case_thms) @ size_thms @ rec_thms; |
845 |
845 |