src/HOL/Datatype_Examples/Misc_Datatype.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_Datatype.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 datatype definitions.
     8 *)
     9 
    10 header {* Miscellaneous Datatype Definitions *}
    11 
    12 theory Misc_Datatype
    13 imports "~~/src/HOL/Library/Countable" "~~/src/HOL/Library/FSet"
    14 begin
    15 
    16 datatype (discs_sels) simple = X1 | X2 | X3 | X4
    17 
    18 datatype (discs_sels) simple' = X1' unit | X2' unit | X3' unit | X4' unit
    19 
    20 datatype (discs_sels) simple'' = X1'' nat int | X2''
    21 
    22 datatype (discs_sels) 'a mylist = MyNil | MyCons (myhd: 'a) (mytl: "'a mylist")
    23 
    24 datatype (discs_sels) ('b, 'c :: ord, 'd, 'e) some_passive =
    25   SP1 "('b, 'c, 'd, 'e) some_passive" | SP2 'b | SP3 'c | SP4 'd | SP5 'e
    26 
    27 datatype (discs_sels) 'a multi_live_direct1 = MultiLiveDirect1 'a
    28 datatype (discs_sels) 'a multi_live_direct2 = MultiLiveDirect2 'a 'a
    29 datatype (discs_sels) 'a multi_live_direct3 = MultiLiveDirect3 'a 'a 'a
    30 datatype (discs_sels) 'a multi_live_direct4 = MultiLiveDirect4 'a 'a 'a 'a
    31 datatype (discs_sels) 'a multi_live_direct5 = MultiLiveDirect5 'a 'a 'a 'a 'a
    32 datatype (discs_sels) 'a multi_live_direct6 = MultiLiveDirect6 'a 'a 'a 'a 'a 'a
    33 datatype (discs_sels) 'a multi_live_direct7 = MultiLiveDirect7 'a 'a 'a 'a 'a 'a 'a
    34 datatype (discs_sels) 'a multi_live_direct8 = MultiLiveDirect8 'a 'a 'a 'a 'a 'a 'a 'a
    35 datatype (discs_sels) 'a multi_live_direct9 = MultiLiveDirect9 'a 'a 'a 'a 'a 'a 'a 'a 'a
    36 
    37 datatype 'a live_and_fun = LiveAndFun nat "nat \<Rightarrow> 'a"
    38 
    39 datatype (discs_sels) hfset = HFset "hfset fset"
    40 
    41 datatype (discs_sels) lambda =
    42   Var string |
    43   App lambda lambda |
    44   Abs string lambda |
    45   Let "(string \<times> lambda) fset" lambda
    46 
    47 datatype (discs_sels) '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 datatype (discs_sels) 'a I1 = I11 'a "'a I1" | I12 'a "'a I2"
    59 and 'a I2 = I21 | I22 "'a I1" "'a I2"
    60 
    61 datatype (discs_sels) 'a tree = TEmpty | TNode 'a "'a forest"
    62 and 'a forest = FNil | FCons "'a tree" "'a forest"
    63 
    64 datatype (discs_sels) 'a tree' = TEmpty' | TNode' "'a branch" "'a branch"
    65 and 'a branch = Branch 'a "'a tree'"
    66 
    67 datatype (discs_sels) 'a bin_rose_tree = BRTree 'a "'a bin_rose_tree mylist" "'a bin_rose_tree mylist"
    68 
    69 datatype (discs_sels) ('a, 'b) exp = Term "('a, 'b) trm" | Sum "('a, 'b) trm" "('a, 'b) exp"
    70 and ('a, 'b) trm = Factor "('a, 'b) factor" | Prod "('a, 'b) factor" "('a, 'b) trm"
    71 and ('a, 'b) factor = C 'a | V 'b | Paren "('a, 'b) exp"
    72 
    73 datatype (discs_sels) 'a ftree = FTLeaf 'a | FTNode "'a \<Rightarrow> 'a ftree"
    74 
    75 datatype (discs_sels) ('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 datatype (discs_sels) 'b nofail1 = NF11 "'b nofail1" 'b | NF12 'b
    81 datatype (discs_sels) 'b nofail2 = NF2 "('b nofail2 \<times> 'b \<times> 'b nofail2 \<times> 'b) list"
    82 datatype (discs_sels) 'b nofail3 = NF3 'b "('b nofail3 \<times> 'b \<times> 'b nofail3 \<times> 'b) fset"
    83 datatype (discs_sels) 'b nofail4 = NF4 "('b nofail4 \<times> ('b nofail4 \<times> 'b \<times> 'b nofail4 \<times> 'b) fset) list"
    84 
    85 (*
    86 datatype (discs_sels) 'b fail = F "'b fail" 'b "'b fail" "'b list"
    87 datatype (discs_sels) 'b fail = F "'b fail" 'b "'b fail" 'b
    88 datatype (discs_sels) 'b fail = F1 "'b fail" 'b | F2 "'b fail"
    89 datatype (discs_sels) 'b fail = F "'b fail" 'b
    90 *)
    91 
    92 datatype (discs_sels) l1 = L1 "l2 list"
    93 and l2 = L21 "l1 fset" | L22 l2
    94 
    95 datatype (discs_sels) kk1 = KK1 kk2
    96 and kk2 = KK2 kk3
    97 and kk3 = KK3 "kk1 list"
    98 
    99 datatype (discs_sels) t1 = T11 t3 | T12 t2
   100 and t2 = T2 t1
   101 and t3 = T3
   102 
   103 datatype (discs_sels) t1' = T11' t2' | T12' t3'
   104 and t2' = T2' t1'
   105 and t3' = T3'
   106 
   107 (*
   108 datatype (discs_sels) fail1 = F1 fail2
   109 and fail2 = F2 fail3
   110 and fail3 = F3 fail1
   111 
   112 datatype (discs_sels) fail1 = F1 "fail2 list" fail2
   113 and fail2 = F2 "fail2 fset" fail3
   114 and fail3 = F3 fail1
   115 
   116 datatype (discs_sels) fail1 = F1 "fail2 list" fail2
   117 and fail2 = F2 "fail1 fset" fail1
   118 *)
   119 
   120 (* SLOW
   121 datatype (discs_sels) ('a, 'c) D1 = A1 "('a, 'c) D2" | B1 "'a list"
   122 and ('a, 'c) D2 = A2 "('a, 'c) D3" | B2 "'c list"
   123 and ('a, 'c) D3 = A3 "('a, 'c) D3" | B3 "('a, 'c) D4" | C3 "('a, 'c) D4" "('a, 'c) D5"
   124 and ('a, 'c) D4 = A4 "('a, 'c) D5" | B4 "'a list list list"
   125 and ('a, 'c) D5 = A5 "('a, 'c) D6"
   126 and ('a, 'c) D6 = A6 "('a, 'c) D7"
   127 and ('a, 'c) D7 = A7 "('a, 'c) D8"
   128 and ('a, 'c) D8 = A8 "('a, 'c) D1 list"
   129 *)
   130 
   131 (* fail:
   132 datatype (discs_sels) tt1 = TT11 tt2 tt3 | TT12 tt2 tt4
   133 and tt2 = TT2
   134 and tt3 = TT3 tt4
   135 and tt4 = TT4 tt1
   136 *)
   137 
   138 datatype (discs_sels) k1 = K11 k2 k3 | K12 k2 k4
   139 and k2 = K2
   140 and k3 = K3 k4
   141 and k4 = K4
   142 
   143 datatype (discs_sels) tt1 = TT11 tt3 tt2 | TT12 tt2 tt4
   144 and tt2 = TT2
   145 and tt3 = TT3 tt1
   146 and tt4 = TT4
   147 
   148 (* SLOW
   149 datatype (discs_sels) s1 = S11 s2 s3 s4 | S12 s3 | S13 s2 s6 | S14 s4 s2 | S15 s2 s2
   150 and s2 = S21 s7 s5 | S22 s5 s4 s6
   151 and s3 = S31 s1 s7 s2 | S32 s3 s3 | S33 s4 s5
   152 and s4 = S4 s5
   153 and s5 = S5
   154 and s6 = S61 s6 | S62 s1 s2 | S63 s6
   155 and s7 = S71 s8 | S72 s5
   156 and s8 = S8 nat
   157 *)
   158 
   159 datatype (discs_sels) 'a deadbar = DeadBar "'a \<Rightarrow> 'a"
   160 datatype (discs_sels) 'a deadbar_option = DeadBarOption "'a option \<Rightarrow> 'a option"
   161 datatype (discs_sels) ('a, 'b) bar = Bar "'b \<Rightarrow> 'a"
   162 datatype (discs_sels) ('a, 'b, 'c, 'd) foo = Foo "'d + 'b \<Rightarrow> 'c + 'a"
   163 datatype (discs_sels) 'a deadfoo = DeadFoo "'a \<Rightarrow> 'a + 'a"
   164 
   165 datatype (discs_sels) (dead 'a) dead_foo = A
   166 datatype (discs_sels) ('a, 'b) use_dead_foo = Y 'a "'b dead_foo"
   167 
   168 datatype (discs_sels) 'a phantom = A
   169 datatype (discs_sels) 'a use_phantom = Y 'a "'a use_phantom phantom"
   170 
   171 datatype ('t, 'id) dead_sum_fun = Dead_sum_fun "('t list \<Rightarrow> 't) + 't" | Bar (bar: 'id)
   172 
   173 datatype (discs_sels) d1 = D
   174 datatype (discs_sels) d1' = is_D: D
   175 
   176 datatype (discs_sels) d2 = D nat
   177 datatype (discs_sels) d2' = is_D: D nat
   178 
   179 datatype (discs_sels) d3 = D | E
   180 datatype (discs_sels) d3' = D | is_E: E
   181 datatype (discs_sels) d3'' = is_D: D | E
   182 datatype (discs_sels) d3''' = is_D: D | is_E: E
   183 
   184 datatype (discs_sels) d4 = D nat | E
   185 datatype (discs_sels) d4' = D nat | is_E: E
   186 datatype (discs_sels) d4'' = is_D: D nat | E
   187 datatype (discs_sels) d4''' = is_D: D nat | is_E: E
   188 
   189 datatype (discs_sels) d5 = D nat | E int
   190 datatype (discs_sels) d5' = D nat | is_E: E int
   191 datatype (discs_sels) d5'' = is_D: D nat | E int
   192 datatype (discs_sels) d5''' = is_D: D nat | is_E: E int
   193 
   194 instance simple :: countable
   195   by countable_datatype
   196 
   197 instance simple'' :: countable
   198   by countable_datatype
   199 
   200 instance mylist :: (countable) countable
   201   by countable_datatype
   202 
   203 instance some_passive :: (countable, "{countable,ord}", countable, countable) countable
   204   by countable_datatype
   205 
   206 (* TODO: Enable once "fset" is registered as countable:
   207 
   208 instance hfset :: countable
   209   by countable_datatype
   210 
   211 instance lambda :: countable
   212   by countable_datatype
   213 
   214 instance par_lambda :: (countable) countable
   215   by countable_datatype
   216 *)
   217 
   218 instance I1 and I2 :: (countable) countable
   219   by countable_datatype
   220 
   221 instance tree and forest :: (countable) countable
   222   by countable_datatype
   223 
   224 instance tree' and branch :: (countable) countable
   225   by countable_datatype
   226 
   227 instance bin_rose_tree :: (countable) countable
   228   by countable_datatype
   229 
   230 instance exp and trm and factor :: (countable, countable) countable
   231   by countable_datatype
   232 
   233 instance nofail1 :: (countable) countable
   234   by countable_datatype
   235 
   236 instance nofail2 :: (countable) countable
   237   by countable_datatype
   238 
   239 (* TODO: Enable once "fset" is registered as countable:
   240 
   241 instance nofail3 :: (countable) countable
   242   by countable_datatype
   243 
   244 instance nofail4 :: (countable) countable
   245   by countable_datatype
   246 
   247 instance l1 and l2 :: countable
   248   by countable_datatype
   249 *)
   250 
   251 instance kk1 and kk2 :: countable
   252   by countable_datatype
   253 
   254 instance t1 and t2 and t3 :: countable
   255   by countable_datatype
   256 
   257 instance t1' and t2' and t3' :: countable
   258   by countable_datatype
   259 
   260 instance k1 and k2 and k3 and k4 :: countable
   261   by countable_datatype
   262 
   263 instance tt1 and tt2 and tt3 and tt4 :: countable
   264   by countable_datatype
   265 
   266 instance d1 :: countable
   267   by countable_datatype
   268 
   269 instance d1' :: countable
   270   by countable_datatype
   271 
   272 instance d2 :: countable
   273   by countable_datatype
   274 
   275 instance d2' :: countable
   276   by countable_datatype
   277 
   278 instance d3 :: countable
   279   by countable_datatype
   280 
   281 instance d3' :: countable
   282   by countable_datatype
   283 
   284 instance d3'' :: countable
   285   by countable_datatype
   286 
   287 instance d3''' :: countable
   288   by countable_datatype
   289 
   290 instance d4 :: countable
   291   by countable_datatype
   292 
   293 instance d4' :: countable
   294   by countable_datatype
   295 
   296 instance d4'' :: countable
   297   by countable_datatype
   298 
   299 instance d4''' :: countable
   300   by countable_datatype
   301 
   302 instance d5 :: countable
   303   by countable_datatype
   304 
   305 instance d5' :: countable
   306   by countable_datatype
   307 
   308 instance d5'' :: countable
   309   by countable_datatype
   310 
   311 instance d5''' :: countable
   312   by countable_datatype
   313 
   314 datatype_compat simple
   315 datatype_compat simple'
   316 datatype_compat simple''
   317 datatype_compat mylist
   318 datatype_compat some_passive
   319 datatype_compat I1 I2
   320 datatype_compat tree forest
   321 datatype_compat tree' branch
   322 datatype_compat bin_rose_tree
   323 datatype_compat exp trm factor
   324 datatype_compat ftree
   325 datatype_compat nofail1
   326 datatype_compat kk1 kk2 kk3
   327 datatype_compat t1 t2 t3
   328 datatype_compat t1' t2' t3'
   329 datatype_compat k1 k2 k3 k4
   330 datatype_compat tt1 tt2 tt3 tt4
   331 datatype_compat deadbar
   332 datatype_compat deadbar_option
   333 datatype_compat bar
   334 datatype_compat foo
   335 datatype_compat deadfoo
   336 datatype_compat dead_foo
   337 datatype_compat use_dead_foo
   338 datatype_compat d1
   339 datatype_compat d1'
   340 datatype_compat d2
   341 datatype_compat d2'
   342 datatype_compat d3
   343 datatype_compat d3'
   344 datatype_compat d3''
   345 datatype_compat d3'''
   346 datatype_compat d4
   347 datatype_compat d4'
   348 datatype_compat d4''
   349 datatype_compat d4'''
   350 datatype_compat d5
   351 datatype_compat d5'
   352 datatype_compat d5''
   353 datatype_compat d5'''
   354 
   355 end