src/HOL/BNF_Examples/Compat.thy
 changeset 56454 e9e82384e5a1 child 56455 1ff66e72628b
equal inserted replaced
56453:00548d372f02 56454:e9e82384e5a1
`       `
`     1 theory Compat`
`       `
`     2 imports Main`
`       `
`     3 begin`
`       `
`     4 `
`       `
`     5 `
`       `
`     6 datatype_new 'a lst = Nl | Cns 'a "'a lst"`
`       `
`     7 datatype_compat lst`
`       `
`     8 `
`       `
`     9 datatype_new 'b w = W | W' "'b w * 'b list"`
`       `
`    10 (* no support for sums of products`
`       `
`    11 datatype_compat w`
`       `
`    12 *)`
`       `
`    13 `
`       `
`    14 datatype_new ('c, 'b) s = L 'c | R 'b`
`       `
`    15 datatype_new 'd x = X | X' "('d x lst, 'd list) s"`
`       `
`    16 datatype_compat s`
`       `
`    17 datatype_compat x`
`       `
`    18 `
`       `
`    19 datatype_new 'a tttre = TTTre 'a "'a tttre lst lst lst"`
`       `
`    20 datatype_compat tttre`
`       `
`    21 `
`       `
`    22 datatype_new 'a ftre = FEmp | FTre "'a \<Rightarrow> 'a ftre lst"`
`       `
`    23 datatype_compat ftre`
`       `
`    24 `
`       `
`    25 datatype_new 'a btre = BTre 'a "'a btre lst" "'a btre lst"`
`       `
`    26 datatype_compat btre`
`       `
`    27 `
`       `
`    28 datatype_new 'a foo = Foo | Foo' 'a "'a bar" and 'a bar = Bar | Bar' 'a "'a foo"`
`       `
`    29 datatype_compat foo bar`
`       `
`    30 `
`       `
`    31 datatype_new 'a tre = Tre 'a "'a tre lst"`
`       `
`    32 datatype_compat tre`
`       `
`    33 `
`       `
`    34 fun f_tre and f_tres where`
`       `
`    35   "f_tre (Tre a ts) = {a} \<union> f_tres ts"`
`       `
`    36 | "f_tres Nl = {}"`
`       `
`    37 | "f_tres (Cns t ts) = f_tres ts"`
`       `
`    38 `
`       `
`    39 datatype_new 'a f = F 'a and 'a g = G 'a`
`       `
`    40 datatype_new h = H "h f" | H'`
`       `
`    41 datatype_compat f g`
`       `
`    42 datatype_compat h`
`       `
`    43 `
`       `
`    44 datatype_new myunit = MyUnity`
`       `
`    45 datatype_compat myunit`
`       `
`    46 `
`       `
`    47 datatype_new mylist = MyNil | MyCons nat mylist`
`       `
`    48 datatype_compat mylist`
`       `
`    49 `
`       `
`    50 fun f_mylist where`
`       `
`    51   "f_mylist MyNil = 0"`
`       `
`    52 | "f_mylist (MyCons _ xs) = Suc (f_mylist xs)"`
`       `
`    53 `
`       `
`    54 datatype_new foo' = FooNil | FooCons bar' foo' and bar' = Bar`
`       `
`    55 (* FIXME`
`       `
`    56 datatype_compat bar' foo'`
`       `
`    57 `
`       `
`    58 fun f_foo and f_bar where`
`       `
`    59   "f_foo FooNil = 0"`
`       `
`    60 | "f_foo (FooCons bar foo) = Suc (f_foo foo) + f_bar bar"`
`       `
`    61 | "f_bar Bar = Suc 0"`
`       `
`    62 *)`
`       `
`    63 `
`       `
`    64 locale opt begin`
`       `
`    65 `
`       `
`    66 datatype_new 'a opt = Non | Som 'a`
`       `
`    67 datatype_compat opt`
`       `
`    68 `
`       `
`    69 end`
`       `
`    70 `
`       `
`    71 datatype funky = Funky "funky tre" | Funky'`
`       `
`    72 datatype fnky = Fnky "nat tre"`
`       `
`    73 `
`       `
`    74 datatype_new tree = Tree "tree foo"`
`       `
`    75 datatype_compat tree`
`       `
`    76 `
`       `
`    77 ML {* Datatype_Data.get_info @{theory} @{type_name tree} *}`
`       `
`    78 `
`       `
`    79 end`