743 in |
743 in |
744 case reflp_tm of |
744 case reflp_tm of |
745 Const (@{const_name reflp}, _) $ _ => () |
745 Const (@{const_name reflp}, _) $ _ => () |
746 | _ => error "Invalid form of the reflexivity theorem. Use \"reflp R\"." |
746 | _ => error "Invalid form of the reflexivity theorem. Use \"reflp R\"." |
747 end |
747 end |
|
748 |
|
749 fun check_qty qty = if not (is_Type qty) |
|
750 then error "The abstract type must be a type constructor." |
|
751 else () |
748 |
752 |
749 fun setup_quotient () = |
753 fun setup_quotient () = |
750 let |
754 let |
751 val opt_reflp_thm = Option.map (singleton (Attrib.eval_thms lthy)) opt_reflp_xthm |
755 val opt_reflp_thm = Option.map (singleton (Attrib.eval_thms lthy)) opt_reflp_xthm |
752 val _ = if is_some opt_reflp_thm then sanity_check_reflp_thm (the opt_reflp_thm) else () |
756 val _ = if is_some opt_reflp_thm then sanity_check_reflp_thm (the opt_reflp_thm) else () |
753 val opt_par_thm = Option.map (singleton (Attrib.eval_thms lthy)) opt_par_xthm |
757 val opt_par_thm = Option.map (singleton (Attrib.eval_thms lthy)) opt_par_xthm |
|
758 val _ = check_qty (snd (quot_thm_rty_qty input_thm)) |
754 in |
759 in |
755 setup_by_quotient gen_code input_thm opt_reflp_thm opt_par_thm lthy |
760 setup_by_quotient gen_code input_thm opt_reflp_thm opt_par_thm lthy |
756 end |
761 end |
757 |
|
758 |
762 |
759 fun setup_typedef () = |
763 fun setup_typedef () = |
760 case opt_reflp_xthm of |
764 let |
761 SOME _ => error "The reflexivity theorem cannot be specified if the type_definition theorem is used." |
765 val qty = (range_type o fastype_of o hd o get_args 2) input_term |
762 | NONE => ( |
766 val _ = check_qty qty |
763 case opt_par_xthm of |
767 in |
764 SOME _ => error "The parametricity theorem cannot be specified if the type_definition theorem is used." |
768 case opt_reflp_xthm of |
765 | NONE => setup_by_typedef_thm gen_code input_thm lthy |
769 SOME _ => error "The reflexivity theorem cannot be specified if the type_definition theorem is used." |
766 ) |
770 | NONE => ( |
|
771 case opt_par_xthm of |
|
772 SOME _ => error "The parametricity theorem cannot be specified if the type_definition theorem is used." |
|
773 | NONE => setup_by_typedef_thm gen_code input_thm lthy |
|
774 ) |
|
775 end |
767 in |
776 in |
768 case input_term of |
777 case input_term of |
769 (Const (@{const_name Quotient}, _) $ _ $ _ $ _ $ _) => setup_quotient () |
778 (Const (@{const_name Quotient}, _) $ _ $ _ $ _ $ _) => setup_quotient () |
770 | (Const (@{const_name type_definition}, _) $ _ $ _ $ _) => setup_typedef () |
779 | (Const (@{const_name type_definition}, _) $ _ $ _ $ _) => setup_typedef () |
771 | _ => error "Unsupported type of a theorem. Only Quotient or type_definition are supported." |
780 | _ => error "Unsupported type of a theorem. Only Quotient or type_definition are supported." |