src/HOL/Datatype_Examples/Misc_Codatatype.thy
author haftmann
Fri Oct 10 19:55:32 2014 +0200 (2014-10-10)
changeset 58646 cd63a4b12a33
parent 58455 126c353540fc
child 58889 5b7a9633cfa8
permissions -rw-r--r--
specialized specification: avoid trivial instances
     1 (*  Title:      HOL/Datatype_Examples/Misc_Codatatype.thy
     2     Author:     Dmitriy Traytel, TU Muenchen
     3     Author:     Andrei Popescu, TU Muenchen
     4     Author:     Jasmin Blanchette, TU Muenchen
     5     Copyright   2012, 2013
     6 
     7 Miscellaneous codatatype definitions.
     8 *)
     9 
    10 header {* Miscellaneous Codatatype Definitions *}
    11 
    12 theory Misc_Codatatype
    13 imports "~~/src/HOL/Library/FSet"
    14 begin
    15 
    16 codatatype simple = X1 | X2 | X3 | X4
    17 
    18 codatatype simple' = X1' unit | X2' unit | X3' unit | X4' unit
    19 
    20 codatatype simple'' = X1'' nat int | X2''
    21 
    22 codatatype 'a stream = Stream (shd: 'a) (stl: "'a stream")
    23 
    24 codatatype 'a mylist = MyNil | MyCons (myhd: 'a) (mytl: "'a mylist")
    25 
    26 codatatype ('b, 'c :: ord, 'd, 'e) some_passive =
    27   SP1 "('b, 'c, 'd, 'e) some_passive" | SP2 'b | SP3 'c | SP4 'd | SP5 'e
    28 
    29 codatatype 'a multi_live_direct1 = MultiLiveDirect1 'a
    30 codatatype 'a multi_live_direct2 = MultiLiveDirect2 'a 'a
    31 codatatype 'a multi_live_direct3 = MultiLiveDirect3 'a 'a 'a
    32 codatatype 'a multi_live_direct4 = MultiLiveDirect4 'a 'a 'a 'a
    33 codatatype 'a multi_live_direct5 = MultiLiveDirect5 'a 'a 'a 'a 'a
    34 codatatype 'a multi_live_direct6 = MultiLiveDirect6 'a 'a 'a 'a 'a 'a
    35 codatatype 'a multi_live_direct7 = MultiLiveDirect7 'a 'a 'a 'a 'a 'a 'a
    36 codatatype 'a multi_live_direct8 = MultiLiveDirect8 'a 'a 'a 'a 'a 'a 'a 'a
    37 codatatype 'a multi_live_direct9 = MultiLiveDirect9 'a 'a 'a 'a 'a 'a 'a 'a 'a
    38 
    39 datatype 'a live_and_fun = LiveAndFun nat "nat \<Rightarrow> 'a"
    40 
    41 codatatype lambda =
    42   Var string |
    43   App lambda lambda |
    44   Abs string lambda |
    45   Let "(string \<times> lambda) fset" lambda
    46 
    47 codatatype 'a par_lambda =
    48   PVar 'a |
    49   PApp "'a par_lambda" "'a par_lambda" |
    50   PAbs 'a "'a par_lambda" |
    51   PLet "('a \<times> 'a par_lambda) fset" "'a par_lambda"
    52 
    53 (*
    54   ('a, 'b1, 'b2) F1 = 'a * 'b1 + 'a * 'b2
    55   ('a, 'b1, 'b2) F2 = unit + 'b1 * 'b2
    56 *)
    57 
    58 codatatype 'a p = P "'a + 'a p"
    59 
    60 codatatype 'a J1 = J11 'a "'a J1" | J12 'a "'a J2"
    61 and 'a J2 = J21 | J22 "'a J1" "'a J2"
    62 
    63 codatatype 'a tree = TEmpty | TNode 'a "'a forest"
    64 and 'a forest = FNil | FCons "'a tree" "'a forest"
    65 
    66 codatatype 'a tree' = TEmpty' | TNode' "'a branch" "'a branch"
    67 and 'a branch = Branch 'a "'a tree'"
    68 
    69 codatatype 'a bin_rose_tree = BRTree 'a "'a bin_rose_tree mylist" "'a bin_rose_tree mylist"
    70 
    71 codatatype ('a, 'b) exp = Term "('a, 'b) trm" | Sum "('a, 'b) trm" "('a, 'b) exp"
    72 and ('a, 'b) trm = Factor "('a, 'b) factor" | Prod "('a, 'b) factor" "('a, 'b) trm"
    73 and ('a, 'b) factor = C 'a | V 'b | Paren "('a, 'b) exp"
    74 
    75 codatatype ('a, 'b, 'c) some_killing =
    76   SK "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b, 'c) some_killing + ('a, 'b, 'c) in_here"
    77 and ('a, 'b, 'c) in_here =
    78   IH1 'b 'a | IH2 'c
    79 
    80 codatatype ('a, 'b, 'c) some_killing' =
    81   SK' "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b, 'c) some_killing' + ('a, 'b, 'c) in_here'"
    82 and ('a, 'b, 'c) in_here' =
    83   IH1' 'b | IH2' 'c
    84 
    85 codatatype ('a, 'b, 'c) some_killing'' =
    86   SK'' "'a \<Rightarrow> ('a, 'b, 'c) in_here''"
    87 and ('a, 'b, 'c) in_here'' =
    88   IH1'' 'b 'a | IH2'' 'c
    89 
    90 codatatype ('b, 'c) less_killing = LK "'b \<Rightarrow> 'c"
    91 
    92 codatatype 'b poly_unit = U "'b \<Rightarrow> 'b poly_unit"
    93 codatatype 'b cps = CPS1 'b | CPS2 "'b \<Rightarrow> 'b cps"
    94 
    95 codatatype ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9) fun_rhs =
    96   FR "'b1 \<Rightarrow> 'b2 \<Rightarrow> 'b3 \<Rightarrow> 'b4 \<Rightarrow> 'b5 \<Rightarrow> 'b6 \<Rightarrow> 'b7 \<Rightarrow> 'b8 \<Rightarrow> 'b9 \<Rightarrow>
    97       ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9) fun_rhs"
    98 
    99 codatatype ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9, 'b10, 'b11, 'b12, 'b13, 'b14, 'b15, 'b16, 'b17,
   100         'b18, 'b19, 'b20) fun_rhs' =
   101   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>
   102        'b15 \<Rightarrow> 'b16 \<Rightarrow> 'b17 \<Rightarrow> 'b18 \<Rightarrow> 'b19 \<Rightarrow> 'b20 \<Rightarrow>
   103        ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9, 'b10, 'b11, 'b12, 'b13, 'b14, 'b15, 'b16, 'b17,
   104         'b18, 'b19, 'b20) fun_rhs'"
   105 
   106 codatatype ('a, 'b, 'c) wit3_F1 = W1 'a "('a, 'b, 'c) wit3_F1" "('a, 'b, 'c) wit3_F2"
   107 and ('a, 'b, 'c) wit3_F2 = W2 'b "('a, 'b, 'c) wit3_F2"
   108 and ('a, 'b, 'c) wit3_F3 = W31 'a 'b "('a, 'b, 'c) wit3_F1" | W32 'c 'a 'b "('a, 'b, 'c) wit3_F1"
   109 
   110 codatatype ('c, 'e, 'g) coind_wit1 =
   111        CW1 'c "('c, 'e, 'g) coind_wit1" "('c, 'e, 'g) ind_wit" "('c, 'e, 'g) coind_wit2"
   112 and ('c, 'e, 'g) coind_wit2 =
   113        CW21 "('c, 'e, 'g) coind_wit2" 'e | CW22 'c 'g
   114 and ('c, 'e, 'g) ind_wit =
   115        IW1 | IW2 'c
   116 
   117 codatatype ('b, 'a) bar = BAR "'a \<Rightarrow> 'b"
   118 codatatype ('a, 'b, 'c, 'd) foo = FOO "'d + 'b \<Rightarrow> 'c + 'a"
   119 
   120 codatatype (dead 'a) dead_foo = A
   121 codatatype ('a, 'b) use_dead_foo = Y 'a "'b dead_foo"
   122 
   123 codatatype 'a phantom = A
   124 codatatype 'a use_phantom = Y 'a "'a use_phantom phantom"
   125 
   126 (* SLOW, MEMORY-HUNGRY
   127 codatatype ('a, 'c) D1 = A1 "('a, 'c) D2" | B1 "'a list"
   128 and ('a, 'c) D2 = A2 "('a, 'c) D3" | B2 "'c list"
   129 and ('a, 'c) D3 = A3 "('a, 'c) D3" | B3 "('a, 'c) D4" | C3 "('a, 'c) D4" "('a, 'c) D5"
   130 and ('a, 'c) D4 = A4 "('a, 'c) D5" | B4 "'a list list list"
   131 and ('a, 'c) D5 = A5 "('a, 'c) D6"
   132 and ('a, 'c) D6 = A6 "('a, 'c) D7"
   133 and ('a, 'c) D7 = A7 "('a, 'c) D8"
   134 and ('a, 'c) D8 = A8 "('a, 'c) D1 list"
   135 *)
   136 
   137 end