src/HOL/Tools/TFL/dcterm.ML
changeset 41164 6854e9a40edc
parent 38864 4abe644fcea5
child 41589 bbd861837ebc
equal deleted inserted replaced
41163:3f21a269780e 41164:6854e9a40edc
    47 end;
    47 end;
    48 
    48 
    49 structure Dcterm: DCTERM =
    49 structure Dcterm: DCTERM =
    50 struct
    50 struct
    51 
    51 
    52 structure U = Utils;
    52 fun ERR func mesg = Utils.ERR {module = "Dcterm", func = func, mesg = mesg};
    53 
       
    54 fun ERR func mesg = U.ERR {module = "Dcterm", func = func, mesg = mesg};
       
    55 
    53 
    56 
    54 
    57 fun dest_comb t = Thm.dest_comb t
    55 fun dest_comb t = Thm.dest_comb t
    58   handle CTERM (msg, _) => raise ERR "dest_comb" msg;
    56   handle CTERM (msg, _) => raise ERR "dest_comb" msg;
    59 
    57 
   108  *---------------------------------------------------------------------------*)
   106  *---------------------------------------------------------------------------*)
   109 
   107 
   110 fun dest_monop expected tm =
   108 fun dest_monop expected tm =
   111  let
   109  let
   112    fun err () = raise ERR "dest_monop" ("Not a(n) " ^ quote expected);
   110    fun err () = raise ERR "dest_monop" ("Not a(n) " ^ quote expected);
   113    val (c, N) = dest_comb tm handle U.ERR _ => err ();
   111    val (c, N) = dest_comb tm handle Utils.ERR _ => err ();
   114    val name = #Name (dest_const c handle U.ERR _ => err ());
   112    val name = #Name (dest_const c handle Utils.ERR _ => err ());
   115  in if name = expected then N else err () end;
   113  in if name = expected then N else err () end;
   116 
   114 
   117 fun dest_binop expected tm =
   115 fun dest_binop expected tm =
   118  let
   116  let
   119    fun err () = raise ERR "dest_binop" ("Not a(n) " ^ quote expected);
   117    fun err () = raise ERR "dest_binop" ("Not a(n) " ^ quote expected);
   120    val (M, N) = dest_comb tm handle U.ERR _ => err ()
   118    val (M, N) = dest_comb tm handle Utils.ERR _ => err ()
   121  in (dest_monop expected M, N) handle U.ERR _ => err () end;
   119  in (dest_monop expected M, N) handle Utils.ERR _ => err () end;
   122 
   120 
   123 fun dest_binder expected tm =
   121 fun dest_binder expected tm =
   124   dest_abs NONE (dest_monop expected tm)
   122   dest_abs NONE (dest_monop expected tm)
   125   handle U.ERR _ => raise ERR "dest_binder" ("Not a(n) " ^ quote expected);
   123   handle Utils.ERR _ => raise ERR "dest_binder" ("Not a(n) " ^ quote expected);
   126 
   124 
   127 
   125 
   128 val dest_neg    = dest_monop @{const_name Not}
   126 val dest_neg    = dest_monop @{const_name Not}
   129 val dest_pair   = dest_binop @{const_name Pair}
   127 val dest_pair   = dest_binop @{const_name Pair}
   130 val dest_eq     = dest_binop @{const_name HOL.eq}
   128 val dest_eq     = dest_binop @{const_name HOL.eq}
   149 
   147 
   150 
   148 
   151 (*---------------------------------------------------------------------------
   149 (*---------------------------------------------------------------------------
   152  * Iterated creation.
   150  * Iterated creation.
   153  *---------------------------------------------------------------------------*)
   151  *---------------------------------------------------------------------------*)
   154 val list_mk_disj = U.end_itlist (fn d1 => fn tm => mk_disj (d1, tm));
   152 val list_mk_disj = Utils.end_itlist (fn d1 => fn tm => mk_disj (d1, tm));
   155 
   153 
   156 (*---------------------------------------------------------------------------
   154 (*---------------------------------------------------------------------------
   157  * Iterated destruction. (To the "right" in a term.)
   155  * Iterated destruction. (To the "right" in a term.)
   158  *---------------------------------------------------------------------------*)
   156  *---------------------------------------------------------------------------*)
   159 fun strip break tm =
   157 fun strip break tm =
   160   let fun dest (p as (ctm,accum)) =
   158   let fun dest (p as (ctm,accum)) =
   161         let val (M,N) = break ctm
   159         let val (M,N) = break ctm
   162         in dest (N, M::accum)
   160         in dest (N, M::accum)
   163         end handle U.ERR _ => p
   161         end handle Utils.ERR _ => p
   164   in dest (tm,[])
   162   in dest (tm,[])
   165   end;
   163   end;
   166 
   164 
   167 fun rev2swap (x,l) = (rev l, x);
   165 fun rev2swap (x,l) = (rev l, x);
   168 
   166 
   188     else Thm.cterm_of thy (HOLogic.mk_Trueprop t)
   186     else Thm.cterm_of thy (HOLogic.mk_Trueprop t)
   189   end
   187   end
   190   handle TYPE (msg, _, _) => raise ERR "mk_prop" msg
   188   handle TYPE (msg, _, _) => raise ERR "mk_prop" msg
   191     | TERM (msg, _) => raise ERR "mk_prop" msg;
   189     | TERM (msg, _) => raise ERR "mk_prop" msg;
   192 
   190 
   193 fun drop_prop ctm = dest_monop @{const_name Trueprop} ctm handle U.ERR _ => ctm;
   191 fun drop_prop ctm = dest_monop @{const_name Trueprop} ctm handle Utils.ERR _ => ctm;
   194 
   192 
   195 
   193 
   196 end;
   194 end;