373 val dest_funT = \<^Type_fn>\<open>fun A B => \<open>(A, B)\<close>\<close>; |
373 val dest_funT = \<^Type_fn>\<open>fun A B => \<open>(A, B)\<close>\<close>; |
374 fun mk_conj (A, B) = \<^Const>\<open>conj for A B\<close>; |
374 fun mk_conj (A, B) = \<^Const>\<open>conj for A B\<close>; |
375 val dest_conj = \<^Const_fn>\<open>conj for A B => \<open>(A, B)\<close>\<close>; |
375 val dest_conj = \<^Const_fn>\<open>conj for A B => \<open>(A, B)\<close>\<close>; |
376 fun mk_eq T (t, u) = \<^Const>\<open>HOL.eq T for t u\<close>; |
376 fun mk_eq T (t, u) = \<^Const>\<open>HOL.eq T for t u\<close>; |
377 val dest_eq = \<^Const_fn>\<open>HOL.eq T for t u => \<open>(T, (t, u))\<close>\<close>; |
377 val dest_eq = \<^Const_fn>\<open>HOL.eq T for t u => \<open>(T, (t, u))\<close>\<close>; |
|
378 |
|
379 * ML antiquotation "instantiate" allows to instantiate formal entities |
|
380 (types, terms, theorems) with values given ML. This works uniformly for |
|
381 "typ", "term", "prop", "ctyp", "cterm", "cprop", "lemma" --- given as a |
|
382 keyword after the instantiation. A mode "(schematic)" behind the keyword |
|
383 means that some variables may remain uninstantiated (fixed in the |
|
384 specification and schematic in the result); by default, all variables |
|
385 need to be instantiated. |
|
386 |
|
387 Examples in HOL: |
|
388 |
|
389 fun make_assoc_type (A, B) = |
|
390 \<^instantiate>\<open>'a = A and 'b = B in typ \<open>('a \<times> 'b) list\<close>\<close>; |
|
391 |
|
392 val make_assoc_list = |
|
393 map (fn (x, y) => |
|
394 \<^instantiate>\<open>'a = \<open>fastype_of x\<close> and 'b = \<open>fastype_of y\<close> and |
|
395 x and y in term \<open>(x, y)\<close> for x :: 'a and y :: 'b\<close>); |
|
396 |
|
397 fun symmetry x y = |
|
398 \<^instantiate>\<open>'a = \<open>Thm.ctyp_of_cterm x\<close> and x and y in |
|
399 lemma \<open>x = y \<Longrightarrow> y = x\<close> for x y :: 'a by simp\<close> |
|
400 |
|
401 fun symmetry_schematic A = |
|
402 \<^instantiate>\<open>'a = A in |
|
403 lemma (schematic) \<open>x = y \<Longrightarrow> y = x\<close> for x y :: 'a by simp\<close> |
378 |
404 |
379 * The "build" combinators of various data structures help to build |
405 * The "build" combinators of various data structures help to build |
380 content from bottom-up, by applying an "add" function the "empty" value. |
406 content from bottom-up, by applying an "add" function the "empty" value. |
381 For example: |
407 For example: |
382 |
408 |