# HG changeset patch # User blanchet # Date 1409581067 -7200 # Node ID c60617a84c1d23d5cfaf28e90b60115bb22422e4 # Parent 62765d39539f8e0580fed1f2159e0a57bc2fdd4f added compatibility examples/tests diff -r 62765d39539f -r c60617a84c1d src/HOL/BNF_Examples/Compat.thy --- a/src/HOL/BNF_Examples/Compat.thy Mon Sep 01 16:17:47 2014 +0200 +++ b/src/HOL/BNF_Examples/Compat.thy Mon Sep 01 16:17:47 2014 +0200 @@ -11,57 +11,153 @@ imports Main begin +ML \ +fun check_len n xs label = + length xs = n orelse error ("Expected length " ^ string_of_int (length xs) ^ " for " ^ label); + +fun check_lens (n1, n2, n3) (xs1, xs2, xs3) = + check_len n1 xs1 "old" andalso check_len n2 xs2 "unfold" andalso check_len n3 xs3 "keep"; + +fun get_descrs thy lens T_name = + (these (Option.map #descr (Old_Datatype_Data.get_info thy T_name)), + these (Option.map #descr (BNF_LFP_Compat.get_info thy BNF_LFP_Compat.Unfold_Nesting T_name)), + these (Option.map #descr (BNF_LFP_Compat.get_info thy BNF_LFP_Compat.Keep_Nesting T_name))) + |> tap (check_lens lens); +\ + +datatype 'a old_lst = Old_Nl | Old_Cns 'a "'a old_lst" + +ML \ get_descrs @{theory} (1, 1, 1) @{type_name old_lst} \ + datatype_new 'a lst = Nl | Cns 'a "'a lst" + +ML \ get_descrs @{theory} (0, 1, 1) @{type_name lst} \ + datatype_compat lst +ML \ get_descrs @{theory} (1, 1, 1) @{type_name lst} \ + datatype_new 'b w = W | W' "'b w \ 'b list" -(* no support for sums of products + +(* no support for sums of products: datatype_compat w *) +ML \ get_descrs @{theory} (0, 1, 1) @{type_name w} \ + datatype_new ('c, 'b) s = L 'c | R 'b + +ML \ get_descrs @{theory} (0, 1, 1) @{type_name s} \ + datatype_new 'd x = X | X' "('d x lst, 'd list) s" + +ML \ get_descrs @{theory} (0, 1, 1) @{type_name x} \ + datatype_compat s + +ML \ get_descrs @{theory} (1, 1, 1) @{type_name s} \ +ML \ get_descrs @{theory} (0, 3, 1) @{type_name x} \ + datatype_compat x +ML \ get_descrs @{theory} (3, 3, 1) @{type_name x} \ + datatype_new 'a tttre = TTTre 'a "'a tttre lst lst lst" + +ML \ get_descrs @{theory} (0, 4, 1) @{type_name tttre} \ + datatype_compat tttre +ML \ get_descrs @{theory} (4, 4, 1) @{type_name tttre} \ + datatype_new 'a ftre = FEmp | FTre "'a \ 'a ftre lst" + +ML \ get_descrs @{theory} (0, 2, 1) @{type_name ftre} \ + datatype_compat ftre +ML \ get_descrs @{theory} (2, 2, 1) @{type_name ftre} \ + datatype_new 'a btre = BTre 'a "'a btre lst" "'a btre lst" + +ML \ get_descrs @{theory} (0, 3, 1) @{type_name btre} \ + datatype_compat btre +ML \ get_descrs @{theory} (3, 3, 1) @{type_name btre} \ + datatype_new 'a foo = Foo | Foo' 'a "'a bar" and 'a bar = Bar | Bar' 'a "'a foo" + +ML \ get_descrs @{theory} (0, 2, 2) @{type_name foo} \ +ML \ get_descrs @{theory} (0, 2, 2) @{type_name bar} \ + datatype_compat foo bar +ML \ get_descrs @{theory} (2, 2, 2) @{type_name foo} \ +ML \ get_descrs @{theory} (2, 2, 2) @{type_name bar} \ + datatype_new 'a tre = Tre 'a "'a tre lst" + +ML \ get_descrs @{theory} (0, 2, 1) @{type_name tre} \ + datatype_compat tre +ML \ get_descrs @{theory} (2, 2, 1) @{type_name tre} \ + fun f_tre and f_tres where "f_tre (Tre a ts) = {a} \ f_tres ts" | "f_tres Nl = {}" | "f_tres (Cns t ts) = f_tres ts" datatype_new 'a f = F 'a and 'a g = G 'a + +ML \ get_descrs @{theory} (0, 2, 2) @{type_name f} \ +ML \ get_descrs @{theory} (0, 2, 2) @{type_name g} \ + datatype_new h = H "h f" | H' + +ML \ get_descrs @{theory} (0, 1, 1) @{type_name h} \ + datatype_compat f g + +ML \ get_descrs @{theory} (2, 2, 2) @{type_name f} \ +ML \ get_descrs @{theory} (2, 2, 2) @{type_name g} \ +ML \ get_descrs @{theory} (0, 3, 1) @{type_name h} \ + datatype_compat h +ML \ get_descrs @{theory} (3, 3, 1) @{type_name h} \ + datatype_new myunit = MyUnity + +ML \ get_descrs @{theory} (0, 1, 1) @{type_name myunit} \ + datatype_compat myunit +ML \ get_descrs @{theory} (1, 1, 1) @{type_name myunit} \ + datatype_new mylist = MyNil | MyCons nat mylist + +ML \ get_descrs @{theory} (0, 1, 1) @{type_name mylist} \ + datatype_compat mylist +ML \ get_descrs @{theory} (1, 1, 1) @{type_name mylist} \ + fun f_mylist where "f_mylist MyNil = 0" | "f_mylist (MyCons _ xs) = Suc (f_mylist xs)" datatype_new foo' = FooNil | FooCons bar' foo' and bar' = Bar + +ML \ get_descrs @{theory} (0, 2, 2) @{type_name foo'} \ +ML \ get_descrs @{theory} (0, 2, 2) @{type_name bar'} \ + datatype_compat bar' foo' +ML \ get_descrs @{theory} (2, 2, 2) @{type_name foo'} \ +ML \ get_descrs @{theory} (2, 2, 2) @{type_name bar'} \ + fun f_foo and f_bar where "f_foo FooNil = 0" | "f_foo (FooCons bar foo) = Suc (f_foo foo) + f_bar bar" @@ -70,16 +166,29 @@ locale opt begin datatype_new 'a opt = Non | Som 'a + +ML \ get_descrs @{theory} (0, 1, 1) @{type_name opt} \ + datatype_compat opt +ML \ get_descrs @{theory} (1, 1, 1) @{type_name opt} \ + end datatype funky = Funky "funky tre" | Funky' + +ML \ get_descrs @{theory} (3, 3, 3) @{type_name funky} \ + datatype fnky = Fnky "nat tre" +ML \ get_descrs @{theory} (1, 1, 1) @{type_name fnky} \ + datatype_new tree = Tree "tree foo" + +ML \ get_descrs @{theory} (0, 3, 1) @{type_name tree} \ + datatype_compat tree -ML {* Old_Datatype_Data.get_info @{theory} @{type_name tree} *} +ML \ get_descrs @{theory} (3, 3, 1) @{type_name tree} \ end