src/HOL/Library/Phantom_Type.thy
author Andreas Lochbihler
Fri Sep 20 10:09:16 2013 +0200 (2013-09-20)
changeset 53745 788730ab7da4
parent 52147 9943f8067f11
child 58249 180f1b3508ed
permissions -rw-r--r--
prefer Code.abort over code_abort
     1 (*  Title:      HOL/Library/Phantom_Type.thy
     2     Author:     Andreas Lochbihler
     3 *)
     4 
     5 header {* A generic phantom type *}
     6 
     7 theory Phantom_Type
     8 imports Main
     9 begin
    10 
    11 datatype ('a, 'b) phantom = phantom 'b
    12 
    13 primrec of_phantom :: "('a, 'b) phantom \<Rightarrow> 'b" 
    14 where "of_phantom (phantom x) = x"
    15 
    16 lemma of_phantom_phantom [simp]: "phantom (of_phantom x) = x"
    17 by(cases x) simp
    18 
    19 lemma type_definition_phantom': "type_definition of_phantom phantom UNIV"
    20 by(unfold_locales) simp_all
    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 {*
    31   let
    32     fun phantom_tr' ctxt (Type (@{type_name fun}, [_, Type (@{type_name phantom}, [T, _])])) ts =
    33           list_comb
    34             (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