48163
|
1 |
(* Title: HOL/Library/Phantom_Type.thy
|
|
2 |
Author: Andreas Lochbihler
|
|
3 |
*)
|
|
4 |
|
|
5 |
header {* A generic phantom type *}
|
|
6 |
|
|
7 |
theory Phantom_Type imports "~~/src/HOL/Main" begin
|
|
8 |
|
|
9 |
datatype ('a, 'b) phantom = phantom 'b
|
|
10 |
|
|
11 |
primrec of_phantom :: "('a, 'b) phantom \<Rightarrow> 'b"
|
|
12 |
where "of_phantom (phantom x) = x"
|
|
13 |
|
|
14 |
lemma of_phantom_phantom [simp]: "phantom (of_phantom x) = x"
|
|
15 |
by(cases x) simp
|
|
16 |
|
|
17 |
lemma type_definition_phantom': "type_definition of_phantom phantom UNIV"
|
|
18 |
by(unfold_locales) simp_all
|
|
19 |
|
|
20 |
setup_lifting (no_code) type_definition_phantom'
|
|
21 |
|
|
22 |
lemma phantom_comp_of_phantom [simp]: "phantom \<circ> of_phantom = id"
|
|
23 |
and of_phantom_comp_phantom [simp]: "of_phantom \<circ> phantom = id"
|
|
24 |
by(simp_all add: o_def id_def)
|
|
25 |
|
|
26 |
syntax "_Phantom" :: "type \<Rightarrow> logic" ("(1Phantom/(1'(_')))")
|
|
27 |
translations
|
|
28 |
"Phantom('t)" => "CONST phantom :: _ \<Rightarrow> ('t, _) phantom"
|
|
29 |
|
|
30 |
typed_print_translation (advanced) {*
|
|
31 |
let
|
|
32 |
fun phantom_tr' ctxt
|
|
33 |
(Type (@{type_name fun}, [_, Type (@{type_name phantom}, [T, _])])) ts =
|
|
34 |
Term.list_comb (Syntax.const @{syntax_const "_Phantom"} $ Syntax_Phases.term_of_typ ctxt T, ts)
|
|
35 |
| phantom_tr' _ _ _ = raise Match;
|
|
36 |
in [(@{const_syntax phantom}, phantom_tr')] end
|
|
37 |
*}
|
|
38 |
|
|
39 |
end
|