theory Prelude imports PLogic begin subsection {* Ints *} types HInt = "int lift" instance lift :: (zero) zero .. instance lift :: (one) one .. instance lift :: (number) number .. defs (overloaded) zero_lift_def: "0 \ Def 0" one_lift_def: "1 \ Def 1" number_of_lift_def: "number_of w \ Def (number_of w)" consts even :: "HInt \ tr" odd :: "HInt \ tr" less' :: "'a::ord lift \ 'a lift \ tr" (infixl "`<" 50) plus' :: "'a::plus lift \ 'a lift \ 'a lift" (infixl "`+" 65) defs even_def: "even \ flift2 Parity.even" odd_def: "odd \ flift2 (\x. \ Parity.even x)" less'_def: "less' \ FLIFT x y. Def (x < y)" plus'_def: "plus' \ FLIFT x y. Def (x + y)" subsection {* Tuples *} nonterminals typs syntax "_typs" :: "[type,typs] \ typs" ("_,/ _") "" :: "type \ typs" ("_") "_tupletype" :: "[type, typs] \ type" ("<_,/ _>") translations (type) "" == (type) ">" (type) "" == (type) "a * b" constdefs fst :: "<'a,'b> \ 'a" "fst \ cfst" snd :: "<'a,'b> \ 'b" "snd \ csnd" lemma fst_tuple [simp]: "fst\ = x" by (simp add: fst_def) lemma snd_tuple [simp]: "snd\ = y" by (simp add: snd_def) translations "case s of => t" == "csplit$(LAM x y. t)$s" (* domain ('a,'b) T2 = T2 (lazy fst :: "'a") (lazy snd :: "'b") ("\_,/ _\") syntax T2 :: "type \ type \ type" ("\_,/ _\") domain ('a,'b,'c) T3 = T3 (lazy "'a") (lazy "'b") (lazy "'c") syntax T3 :: "type \ type \ type \ type" ("\_,/ _,/ _\") *) subsection {* Lists *} domain 'a L0 = Nil0 ("[:]") | Cons0 (lazy head :: "'a") (lazy tail :: "'a L0") (infixr "`:" 65) syntax "L0" :: "type \ type" ("[_]") "_L0" :: "args \ 'a L0" ("[:(_):]") translations "[:x, xs:]" == "x `: [:xs:]" "[:x:]" == "x `: [:]" consts length_c :: "['a] \ HInt" fixrec "length_c\[:] = 0" "length_c\(x `: xs) = 1 `+ length_c\xs" consts zip :: "['a] \ ['b] \ ['a * 'b]" fixrec "zip\[:]\ys = [:]" "zip\(x `: xs)\[:] = [:]" "zip\(x `: xs)\(y `: ys) = `: zip\xs\ys" fixpat zip_stricts [simp]: "zip\\\ys" "zip\(x `: xs)\\" subsection {* Either type *} domain ('a,'b) Either = Left (lazy "'a") | Right (lazy "'b") end