src/HOL/ex/Antiquote.thy
author haftmann
Fri, 02 Mar 2012 21:45:45 +0100
changeset 46767 807a5d219c23
parent 44603 a6f9a70d655d
child 56233 797060c19f5c
permissions -rw-r--r--
more fundamental pred-to-set conversions for range and domain by means of inductive_set
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5368
7c8d1c7c876d added Antiquote example;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/ex/Antiquote.thy
7c8d1c7c876d added Antiquote example;
wenzelm
parents:
diff changeset
     2
    Author:     Markus Wenzel, TU Muenchen
7c8d1c7c876d added Antiquote example;
wenzelm
parents:
diff changeset
     3
*)
7c8d1c7c876d added Antiquote example;
wenzelm
parents:
diff changeset
     4
10357
wenzelm
parents: 9297
diff changeset
     5
header {* Antiquotations *}
wenzelm
parents: 9297
diff changeset
     6
35113
1a0c129bb2e0 modernized translations;
wenzelm
parents: 32960
diff changeset
     7
theory Antiquote
1a0c129bb2e0 modernized translations;
wenzelm
parents: 32960
diff changeset
     8
imports Main
1a0c129bb2e0 modernized translations;
wenzelm
parents: 32960
diff changeset
     9
begin
5368
7c8d1c7c876d added Antiquote example;
wenzelm
parents:
diff changeset
    10
11586
wenzelm
parents: 10357
diff changeset
    11
text {*
wenzelm
parents: 10357
diff changeset
    12
  A simple example on quote / antiquote in higher-order abstract
wenzelm
parents: 10357
diff changeset
    13
  syntax.
wenzelm
parents: 10357
diff changeset
    14
*}
wenzelm
parents: 10357
diff changeset
    15
44603
a6f9a70d655d tuned document;
wenzelm
parents: 42284
diff changeset
    16
definition var :: "'a => ('a => nat) => nat"  ("VAR _" [1000] 999)
35113
1a0c129bb2e0 modernized translations;
wenzelm
parents: 32960
diff changeset
    17
  where "var x env = env x"
5368
7c8d1c7c876d added Antiquote example;
wenzelm
parents:
diff changeset
    18
44603
a6f9a70d655d tuned document;
wenzelm
parents: 42284
diff changeset
    19
definition Expr :: "(('a => nat) => nat) => ('a => nat) => nat"
35113
1a0c129bb2e0 modernized translations;
wenzelm
parents: 32960
diff changeset
    20
  where "Expr exp env = exp env"
5368
7c8d1c7c876d added Antiquote example;
wenzelm
parents:
diff changeset
    21
44603
a6f9a70d655d tuned document;
wenzelm
parents: 42284
diff changeset
    22
syntax
a6f9a70d655d tuned document;
wenzelm
parents: 42284
diff changeset
    23
  "_Expr" :: "'a => 'a"  ("EXPR _" [1000] 999)
a6f9a70d655d tuned document;
wenzelm
parents: 42284
diff changeset
    24
35113
1a0c129bb2e0 modernized translations;
wenzelm
parents: 32960
diff changeset
    25
parse_translation {*
42284
326f57825e1a explicit structure Syntax_Trans;
wenzelm
parents: 35113
diff changeset
    26
  [Syntax_Trans.quote_antiquote_tr
326f57825e1a explicit structure Syntax_Trans;
wenzelm
parents: 35113
diff changeset
    27
    @{syntax_const "_Expr"} @{const_syntax var} @{const_syntax Expr}]
35113
1a0c129bb2e0 modernized translations;
wenzelm
parents: 32960
diff changeset
    28
*}
1a0c129bb2e0 modernized translations;
wenzelm
parents: 32960
diff changeset
    29
1a0c129bb2e0 modernized translations;
wenzelm
parents: 32960
diff changeset
    30
print_translation {*
42284
326f57825e1a explicit structure Syntax_Trans;
wenzelm
parents: 35113
diff changeset
    31
  [Syntax_Trans.quote_antiquote_tr'
326f57825e1a explicit structure Syntax_Trans;
wenzelm
parents: 35113
diff changeset
    32
    @{syntax_const "_Expr"} @{const_syntax var} @{const_syntax Expr}]
35113
1a0c129bb2e0 modernized translations;
wenzelm
parents: 32960
diff changeset
    33
*}
8559
fd3753188232 ex/Antiquote.thy made new-style theory;
wenzelm
parents: 5368
diff changeset
    34
9297
wenzelm
parents: 8559
diff changeset
    35
term "EXPR (a + b + c)"
wenzelm
parents: 8559
diff changeset
    36
term "EXPR (a + b + c + VAR x + VAR y + 1)"
wenzelm
parents: 8559
diff changeset
    37
term "EXPR (VAR (f w) + VAR x)"
5368
7c8d1c7c876d added Antiquote example;
wenzelm
parents:
diff changeset
    38
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
    39
term "Expr (\<lambda>env. env x)"    -- {* improper *}
10357
wenzelm
parents: 9297
diff changeset
    40
term "Expr (\<lambda>env. f env)"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
    41
term "Expr (\<lambda>env. f env + env x)"    -- {* improper *}
10357
wenzelm
parents: 9297
diff changeset
    42
term "Expr (\<lambda>env. f env y z)"
wenzelm
parents: 9297
diff changeset
    43
term "Expr (\<lambda>env. f env + g y env)"
wenzelm
parents: 9297
diff changeset
    44
term "Expr (\<lambda>env. f env + g env y + h a env z)"
5368
7c8d1c7c876d added Antiquote example;
wenzelm
parents:
diff changeset
    45
9297
wenzelm
parents: 8559
diff changeset
    46
end