src/HOL/Tools/Function/pattern_split.ML
changeset 54406 a2d18fea844a
parent 42483 39eefaef816a
child 54407 e95831757903
equal deleted inserted replaced
54405:88f6d5b1422f 54406:a2d18fea844a
    28 fun saturate ctxt vs t =
    28 fun saturate ctxt vs t =
    29   fold (fn T => fn (vs, t) => new_var ctxt vs T |> apsnd (curry op $ t))
    29   fold (fn T => fn (vs, t) => new_var ctxt vs T |> apsnd (curry op $ t))
    30     (binder_types (fastype_of t)) (vs, t)
    30     (binder_types (fastype_of t)) (vs, t)
    31 
    31 
    32 
    32 
    33 (* This is copied from "pat_completeness.ML" *)
       
    34 fun inst_constrs_of thy (T as Type (name, _)) =
       
    35   map (fn (Cn,CT) =>
       
    36     Envir.subst_term_types (Sign.typ_match thy (body_type CT, T) Vartab.empty) (Const (Cn, CT)))
       
    37     (the (Datatype.get_constrs thy name))
       
    38   | inst_constrs_of thy T = raise TYPE ("inst_constrs_of", [T], [])
       
    39 
       
    40 
       
    41 fun join ((vs1,sub1), (vs2,sub2)) = (merge (op aconv) (vs1,vs2), sub1 @ sub2)
    33 fun join ((vs1,sub1), (vs2,sub2)) = (merge (op aconv) (vs1,vs2), sub1 @ sub2)
    42 fun join_product (xs, ys) = map_product (curry join) xs ys
    34 fun join_product (xs, ys) = map_product (curry join) xs ys
    43 
    35 
    44 exception DISJ
    36 exception DISJ
    45 
    37 
    47   let
    39   let
    48     exception DISJ
    40     exception DISJ
    49     fun pattern_subtract_subst_aux vs _ (Free v2) = []
    41     fun pattern_subtract_subst_aux vs _ (Free v2) = []
    50       | pattern_subtract_subst_aux vs (v as (Free (_, T))) t' =
    42       | pattern_subtract_subst_aux vs (v as (Free (_, T))) t' =
    51           let
    43           let
    52             fun foo constr =
    44             fun aux constr =
    53               let
    45               let
    54                 val (vs', t) = saturate ctxt vs constr
    46                 val (vs', t) = saturate ctxt vs constr
    55                 val substs = pattern_subtract_subst ctxt vs' t t'
    47                 val substs = pattern_subtract_subst ctxt vs' t t'
    56               in
    48               in
    57                 map (fn (vs, subst) => (vs, (v,t)::subst)) substs
    49                 map (fn (vs, subst) => (vs, (v,t)::subst)) substs
    58               end
    50               end
    59           in
    51           in
    60             maps foo (inst_constrs_of (Proof_Context.theory_of ctxt) T)
    52             maps aux (inst_constrs_of (Proof_Context.theory_of ctxt) T)
    61           end
    53           end
    62      | pattern_subtract_subst_aux vs t t' =
    54      | pattern_subtract_subst_aux vs t t' =
    63          let
    55          let
    64            val (C, ps) = strip_comb t
    56            val (C, ps) = strip_comb t
    65            val (C', qs) = strip_comb t'
    57            val (C', qs) = strip_comb t'