src/HOL/BNF_Examples/Misc_Codatatype.thy
author blanchet
Fri Jan 24 11:51:45 2014 +0100 (2014-01-24)
changeset 55129 26bd1cba3ab5
parent 55076 1e73e090a514
child 55484 9deb5066508f
permissions -rw-r--r--
killed 'More_BNFs' by moving its various bits where they (now) belong
blanchet@55075
     1
(*  Title:      HOL/BNF_Examples/Misc_Codatatype.thy
blanchet@48975
     2
    Author:     Dmitriy Traytel, TU Muenchen
blanchet@48975
     3
    Author:     Andrei Popescu, TU Muenchen
blanchet@52323
     4
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@52323
     5
    Copyright   2012, 2013
blanchet@48975
     6
blanchet@53122
     7
Miscellaneous codatatype definitions.
blanchet@48975
     8
*)
blanchet@48975
     9
blanchet@53122
    10
header {* Miscellaneous Codatatype Definitions *}
blanchet@48975
    11
blanchet@53122
    12
theory Misc_Codatatype
blanchet@55129
    13
imports "~~/src/HOL/Library/FSet"
blanchet@48975
    14
begin
blanchet@48975
    15
blanchet@51804
    16
codatatype simple = X1 | X2 | X3 | X4
blanchet@49158
    17
blanchet@51804
    18
codatatype simple' = X1' unit | X2' unit | X3' unit | X4' unit
blanchet@48975
    19
blanchet@52323
    20
codatatype simple'' = X1'' nat int | X2''
blanchet@52323
    21
blanchet@54193
    22
codatatype 'a stream = Stream (shd: 'a) (stl: "'a stream")
blanchet@49158
    23
blanchet@54193
    24
codatatype 'a mylist = MyNil | MyCons (myhd: 'a) (mytl: "'a mylist")
blanchet@49158
    25
blanchet@51804
    26
codatatype ('b, 'c, 'd, 'e) some_passive =
blanchet@49158
    27
  SP1 "('b, 'c, 'd, 'e) some_passive" | SP2 'b | SP3 'c | SP4 'd | SP5 'e
blanchet@48975
    28
blanchet@51804
    29
codatatype lambda =
blanchet@49158
    30
  Var string |
blanchet@49158
    31
  App lambda lambda |
blanchet@49158
    32
  Abs string lambda |
blanchet@49158
    33
  Let "(string \<times> lambda) fset" lambda
blanchet@48975
    34
blanchet@51804
    35
codatatype 'a par_lambda =
blanchet@49158
    36
  PVar 'a |
blanchet@49158
    37
  PApp "'a par_lambda" "'a par_lambda" |
blanchet@49158
    38
  PAbs 'a "'a par_lambda" |
blanchet@49158
    39
  PLet "('a \<times> 'a par_lambda) fset" "'a par_lambda"
blanchet@48975
    40
blanchet@48975
    41
(*
blanchet@48975
    42
  ('a, 'b1, 'b2) F1 = 'a * 'b1 + 'a * 'b2
blanchet@48975
    43
  ('a, 'b1, 'b2) F2 = unit + 'b1 * 'b2
blanchet@48975
    44
*)
blanchet@48975
    45
blanchet@53591
    46
codatatype 'a p = P "'a + 'a p"
blanchet@53591
    47
blanchet@51804
    48
codatatype 'a J1 = J11 'a "'a J1" | J12 'a "'a J2"
blanchet@51804
    49
and 'a J2 = J21 | J22 "'a J1" "'a J2"
blanchet@48975
    50
blanchet@51804
    51
codatatype 'a tree = TEmpty | TNode 'a "'a forest"
blanchet@51804
    52
and 'a forest = FNil | FCons "'a tree" "'a forest"
blanchet@48975
    53
blanchet@51804
    54
codatatype 'a tree' = TEmpty' | TNode' "'a branch" "'a branch"
blanchet@51804
    55
and 'a branch = Branch 'a "'a tree'"
blanchet@48975
    56
blanchet@51804
    57
codatatype ('a, 'b) exp = Term "('a, 'b) trm" | Sum "('a, 'b) trm" "('a, 'b) exp"
blanchet@51804
    58
and ('a, 'b) trm = Factor "('a, 'b) factor" | Prod "('a, 'b) factor" "('a, 'b) trm"
blanchet@51804
    59
and ('a, 'b) factor = C 'a | V 'b | Paren "('a, 'b) exp"
blanchet@48975
    60
blanchet@51804
    61
codatatype ('a, 'b, 'c) some_killing =
blanchet@49158
    62
  SK "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b, 'c) some_killing + ('a, 'b, 'c) in_here"
blanchet@51804
    63
and ('a, 'b, 'c) in_here =
blanchet@49158
    64
  IH1 'b 'a | IH2 'c
blanchet@48975
    65
blanchet@51804
    66
codatatype ('a, 'b, 'c) some_killing' =
blanchet@49617
    67
  SK' "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b, 'c) some_killing' + ('a, 'b, 'c) in_here'"
blanchet@51804
    68
and ('a, 'b, 'c) in_here' =
blanchet@49617
    69
  IH1' 'b | IH2' 'c
blanchet@48975
    70
blanchet@51804
    71
codatatype ('a, 'b, 'c) some_killing'' =
blanchet@49617
    72
  SK'' "'a \<Rightarrow> ('a, 'b, 'c) in_here''"
blanchet@51804
    73
and ('a, 'b, 'c) in_here'' =
blanchet@49617
    74
  IH1'' 'b 'a | IH2'' 'c
blanchet@48975
    75
blanchet@51804
    76
codatatype ('b, 'c) less_killing = LK "'b \<Rightarrow> 'c"
blanchet@48975
    77
traytel@53588
    78
codatatype 'b poly_unit = U "'b \<Rightarrow> 'b poly_unit"
blanchet@51804
    79
codatatype 'b cps = CPS1 'b | CPS2 "'b \<Rightarrow> 'b cps"
blanchet@49158
    80
blanchet@51804
    81
codatatype ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9) fun_rhs =
blanchet@49158
    82
  FR "'b1 \<Rightarrow> 'b2 \<Rightarrow> 'b3 \<Rightarrow> 'b4 \<Rightarrow> 'b5 \<Rightarrow> 'b6 \<Rightarrow> 'b7 \<Rightarrow> 'b8 \<Rightarrow> 'b9 \<Rightarrow>
blanchet@49158
    83
      ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9) fun_rhs"
traytel@49102
    84
blanchet@51804
    85
codatatype ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9, 'b10, 'b11, 'b12, 'b13, 'b14, 'b15, 'b16, 'b17,
blanchet@49158
    86
        'b18, 'b19, 'b20) fun_rhs' =
blanchet@49158
    87
  FR' "'b1 \<Rightarrow> 'b2 \<Rightarrow> 'b3 \<Rightarrow> 'b4 \<Rightarrow> 'b5 \<Rightarrow> 'b6 \<Rightarrow> 'b7 \<Rightarrow> 'b8 \<Rightarrow> 'b9 \<Rightarrow> 'b10 \<Rightarrow> 'b11 \<Rightarrow> 'b12 \<Rightarrow> 'b13 \<Rightarrow> 'b14 \<Rightarrow>
blanchet@49158
    88
       'b15 \<Rightarrow> 'b16 \<Rightarrow> 'b17 \<Rightarrow> 'b18 \<Rightarrow> 'b19 \<Rightarrow> 'b20 \<Rightarrow>
blanchet@49158
    89
       ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9, 'b10, 'b11, 'b12, 'b13, 'b14, 'b15, 'b16, 'b17,
blanchet@49158
    90
        'b18, 'b19, 'b20) fun_rhs'"
blanchet@49158
    91
blanchet@51804
    92
codatatype ('a, 'b, 'c) wit3_F1 = W1 'a "('a, 'b, 'c) wit3_F1" "('a, 'b, 'c) wit3_F2"
blanchet@51804
    93
and ('a, 'b, 'c) wit3_F2 = W2 'b "('a, 'b, 'c) wit3_F2"
blanchet@51804
    94
and ('a, 'b, 'c) wit3_F3 = W31 'a 'b "('a, 'b, 'c) wit3_F1" | W32 'c 'a 'b "('a, 'b, 'c) wit3_F1"
blanchet@49158
    95
blanchet@51804
    96
codatatype ('c, 'e, 'g) coind_wit1 =
blanchet@49158
    97
       CW1 'c "('c, 'e, 'g) coind_wit1" "('c, 'e, 'g) ind_wit" "('c, 'e, 'g) coind_wit2"
blanchet@51804
    98
and ('c, 'e, 'g) coind_wit2 =
blanchet@49158
    99
       CW21 "('c, 'e, 'g) coind_wit2" 'e | CW22 'c 'g
blanchet@51804
   100
and ('c, 'e, 'g) ind_wit =
blanchet@49158
   101
       IW1 | IW2 'c
traytel@49102
   102
blanchet@51804
   103
codatatype ('b, 'a) bar = BAR "'a \<Rightarrow> 'b"
blanchet@51804
   104
codatatype ('a, 'b, 'c, 'd) foo = FOO "'d + 'b \<Rightarrow> 'c + 'a"
traytel@49185
   105
blanchet@51804
   106
codatatype 'a dead_foo = A
blanchet@51804
   107
codatatype ('a, 'b) use_dead_foo = Y "'a" "'b dead_foo"
traytel@49185
   108
blanchet@48975
   109
(* SLOW, MEMORY-HUNGRY
blanchet@51804
   110
codatatype ('a, 'c) D1 = A1 "('a, 'c) D2" | B1 "'a list"
blanchet@51804
   111
and ('a, 'c) D2 = A2 "('a, 'c) D3" | B2 "'c list"
blanchet@51804
   112
and ('a, 'c) D3 = A3 "('a, 'c) D3" | B3 "('a, 'c) D4" | C3 "('a, 'c) D4" "('a, 'c) D5"
blanchet@51804
   113
and ('a, 'c) D4 = A4 "('a, 'c) D5" | B4 "'a list list list"
blanchet@51804
   114
and ('a, 'c) D5 = A5 "('a, 'c) D6"
blanchet@51804
   115
and ('a, 'c) D6 = A6 "('a, 'c) D7"
blanchet@51804
   116
and ('a, 'c) D7 = A7 "('a, 'c) D8"
blanchet@51804
   117
and ('a, 'c) D8 = A8 "('a, 'c) D1 list"
blanchet@48975
   118
*)
blanchet@48975
   119
blanchet@48975
   120
end