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