src/HOL/Library/OptionalSugar.thy
author wenzelm
Tue Mar 10 10:59:59 2009 +0100 (2009-03-10)
changeset 30404 d03dd6301678
parent 29494 a189c6274c7a
child 30474 52e92009aacb
permissions -rw-r--r--
more robust treatment of (authentic) consts within translations;
nipkow@15469
     1
(*  Title:      HOL/Library/OptionalSugar.thy
nipkow@15469
     2
    Author:     Gerwin Klain, Tobias Nipkow
nipkow@15469
     3
    Copyright   2005 NICTA and TUM
nipkow@15469
     4
*)
nipkow@15476
     5
(*<*)
nipkow@15469
     6
theory OptionalSugar
nipkow@15469
     7
imports LaTeXsugar
nipkow@15469
     8
begin
nipkow@15469
     9
nipkow@22835
    10
(* set *)
nipkow@22835
    11
translations
wenzelm@30404
    12
  "xs" <= "CONST set xs"
nipkow@22835
    13
nipkow@15469
    14
(* append *)
nipkow@15469
    15
syntax (latex output)
nipkow@15469
    16
  "appendL" :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" (infixl "\<^raw:\isacharat>" 65)
nipkow@15469
    17
translations
nipkow@15469
    18
  "appendL xs ys" <= "xs @ ys" 
nipkow@15469
    19
  "appendL (appendL xs ys) zs" <= "appendL xs (appendL ys zs)"
nipkow@15469
    20
nipkow@15469
    21
nipkow@15469
    22
(* aligning equations *)
wenzelm@21210
    23
notation (tab output)
wenzelm@21404
    24
  "op ="  ("(_) \<^raw:}\putisatab\isa{\ >=\<^raw:}\putisatab\isa{> (_)" [50,49] 50) and
wenzelm@19674
    25
  "=="  ("(_) \<^raw:}\putisatab\isa{\ >\<equiv>\<^raw:}\putisatab\isa{> (_)")
nipkow@15469
    26
nipkow@15469
    27
(* Let *)
nipkow@15469
    28
translations 
wenzelm@30404
    29
  "_bind (p,DUMMY) e" <= "_bind p (CONST fst e)"
wenzelm@30404
    30
  "_bind (DUMMY,p) e" <= "_bind p (CONST snd e)"
nipkow@15469
    31
nipkow@15469
    32
  "_tuple_args x (_tuple_args y z)" ==
nipkow@15469
    33
    "_tuple_args x (_tuple_arg (_tuple y z))"
nipkow@15469
    34
wenzelm@30404
    35
  "_bind (Some p) e" <= "_bind p (CONST the e)"
wenzelm@30404
    36
  "_bind (p#DUMMY) e" <= "_bind p (CONST hd e)"
wenzelm@30404
    37
  "_bind (DUMMY#p) e" <= "_bind p (CONST tl e)"
nipkow@15469
    38
haftmann@29494
    39
(* type constraints with spacing *)
haftmann@29494
    40
setup {*
haftmann@29494
    41
let
haftmann@29494
    42
  val typ = SimpleSyntax.read_typ;
haftmann@29494
    43
  val typeT = Syntax.typeT;
haftmann@29494
    44
  val spropT = Syntax.spropT;
haftmann@29494
    45
in
haftmann@29494
    46
  Sign.del_modesyntax_i (Symbol.xsymbolsN, false) [
haftmann@29494
    47
    ("_constrain", typ "logic => type => logic", Mixfix ("_\<Colon>_", [4, 0], 3)),
haftmann@29494
    48
    ("_constrain", [spropT, typeT] ---> spropT, Mixfix ("_\<Colon>_", [4, 0], 3))]
haftmann@29494
    49
  #> Sign.add_modesyntax_i (Symbol.xsymbolsN, false) [
haftmann@29494
    50
      ("_constrain", typ "logic => type => logic", Mixfix ("_ \<Colon>  _", [4, 0], 3)),
haftmann@29494
    51
      ("_constrain", [spropT, typeT] ---> spropT, Mixfix ("_ \<Colon> _", [4, 0], 3))]
haftmann@29494
    52
end
haftmann@29494
    53
*}
haftmann@29494
    54
haftmann@29494
    55
(* sorts as intersections *)
haftmann@29494
    56
setup {*
haftmann@29494
    57
let
haftmann@29494
    58
  val sortT = Type ("sort", []); (*FIXME*)
haftmann@29494
    59
  val classesT = Type ("classes", []); (*FIXME*)
haftmann@29494
    60
in
haftmann@29494
    61
  Sign.add_modesyntax_i (Symbol.xsymbolsN, false) [
haftmann@29494
    62
    ("_topsort", sortT, Mixfix ("\<top>", [], Syntax.max_pri)),
haftmann@29494
    63
    ("_sort", classesT --> sortT, Mixfix ("'(_')", [], Syntax.max_pri)),
haftmann@29494
    64
    ("_classes", Lexicon.idT --> classesT --> classesT, Mixfix ("_ \<inter> _", [], Syntax.max_pri)),
haftmann@29494
    65
    ("_classes", Lexicon.longidT --> classesT --> classesT, Mixfix ("_ \<inter> _", [], Syntax.max_pri))
haftmann@29494
    66
  ]
haftmann@29494
    67
end
haftmann@29494
    68
*}
nipkow@15469
    69
nipkow@15476
    70
end
nipkow@15476
    71
(*>*)