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