src/HOL/Library/Phantom_Type.thy
author Andreas Lochbihler
Wed Feb 27 10:33:30 2013 +0100 (2013-02-27)
changeset 51288 be7e9a675ec9
parent 48163 f0ecc1550998
child 51301 6822aa82aafa
permissions -rw-r--r--
add wellorder instance for Numeral_Type (suggested by Jesus Aransay)
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
Andreas@48163
     7
theory Phantom_Type imports "~~/src/HOL/Main" begin
Andreas@48163
     8
Andreas@48163
     9
datatype ('a, 'b) phantom = phantom 'b
Andreas@48163
    10
Andreas@48163
    11
primrec of_phantom :: "('a, 'b) phantom \<Rightarrow> 'b" 
Andreas@48163
    12
where "of_phantom (phantom x) = x"
Andreas@48163
    13
Andreas@48163
    14
lemma of_phantom_phantom [simp]: "phantom (of_phantom x) = x"
Andreas@48163
    15
by(cases x) simp
Andreas@48163
    16
Andreas@48163
    17
lemma type_definition_phantom': "type_definition of_phantom phantom UNIV"
Andreas@48163
    18
by(unfold_locales) simp_all
Andreas@48163
    19
Andreas@48163
    20
setup_lifting (no_code) type_definition_phantom'
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
Andreas@48163
    30
typed_print_translation (advanced) {*
Andreas@48163
    31
let
Andreas@48163
    32
  fun phantom_tr' ctxt 
Andreas@48163
    33
      (Type (@{type_name fun}, [_, Type (@{type_name phantom}, [T, _])])) ts =
Andreas@48163
    34
    Term.list_comb (Syntax.const @{syntax_const "_Phantom"} $ Syntax_Phases.term_of_typ ctxt T, ts)
Andreas@48163
    35
  | phantom_tr' _ _ _ = raise Match;
Andreas@48163
    36
in [(@{const_syntax phantom}, phantom_tr')] end
Andreas@48163
    37
*}
Andreas@48163
    38
Andreas@48163
    39
end