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