equal
deleted
inserted
replaced
38 fun check_constr_pattern (Bound _) = () |
38 fun check_constr_pattern (Bound _) = () |
39 | check_constr_pattern t = |
39 | check_constr_pattern t = |
40 let |
40 let |
41 val (hd, args) = strip_comb t |
41 val (hd, args) = strip_comb t |
42 in |
42 in |
43 (((case Datatype.datatype_of_constr thy (fst (dest_Const hd)) of |
43 (((case Datatype.info_of_constr thy (fst (dest_Const hd)) of |
44 SOME _ => () |
44 SOME _ => () |
45 | NONE => err "Non-constructor pattern") |
45 | NONE => err "Non-constructor pattern") |
46 handle TERM ("dest_Const", _) => err "Non-constructor patterns"); |
46 handle TERM ("dest_Const", _) => err "Non-constructor patterns"); |
47 map check_constr_pattern args; |
47 map check_constr_pattern args; |
48 ()) |
48 ()) |
101 else filter_pats thy cons pvars pts |
101 else filter_pats thy cons pvars pts |
102 |
102 |
103 |
103 |
104 fun inst_constrs_of thy (T as Type (name, _)) = |
104 fun inst_constrs_of thy (T as Type (name, _)) = |
105 map (fn (Cn,CT) => Envir.subst_TVars (Sign.typ_match thy (body_type CT, T) Vartab.empty) (Const (Cn, CT))) |
105 map (fn (Cn,CT) => Envir.subst_TVars (Sign.typ_match thy (body_type CT, T) Vartab.empty) (Const (Cn, CT))) |
106 (the (Datatype.get_datatype_constrs thy name)) |
106 (the (Datatype.get_constrs thy name)) |
107 | inst_constrs_of thy _ = raise Match |
107 | inst_constrs_of thy _ = raise Match |
108 |
108 |
109 |
109 |
110 fun transform_pat thy avars c_assum ([] , thm) = raise Match |
110 fun transform_pat thy avars c_assum ([] , thm) = raise Match |
111 | transform_pat thy avars c_assum (pat :: pats, thm) = |
111 | transform_pat thy avars c_assum (pat :: pats, thm) = |
142 (pats, refl RS (inst_free (cterm_of thy pv) (cterm_of thy v) thm))) pts) |
142 (pats, refl RS (inst_free (cterm_of thy pv) (cterm_of thy v) thm))) pts) |
143 else (* Cons case *) |
143 else (* Cons case *) |
144 let |
144 let |
145 val T = fastype_of v |
145 val T = fastype_of v |
146 val (tname, _) = dest_Type T |
146 val (tname, _) = dest_Type T |
147 val {exhaustion=case_thm, ...} = Datatype.the_datatype thy tname |
147 val {exhaustion=case_thm, ...} = Datatype.the_info thy tname |
148 val constrs = inst_constrs_of thy T |
148 val constrs = inst_constrs_of thy T |
149 val c_cases = map (constr_case thy P idx (v :: vs) pts) constrs |
149 val c_cases = map (constr_case thy P idx (v :: vs) pts) constrs |
150 in |
150 in |
151 inst_case_thm thy v P case_thm |
151 inst_case_thm thy v P case_thm |
152 |> fold (curry op COMP) c_cases |
152 |> fold (curry op COMP) c_cases |