# Theory Candidates

```
(* Author: Florian Haftmann, TU Muenchen *)

section ‹A huge collection of equations to generate code from›

theory Candidates
imports
Complex_Main
"HOL-Library.Library"
"HOL-Library.Sorting_Algorithms"
"HOL-Library.Subseq_Order"
"HOL-Library.RBT"
"HOL-Data_Structures.Tree_Map"
"HOL-Data_Structures.Tree_Set"
"HOL-Computational_Algebra.Computational_Algebra"
"HOL-Computational_Algebra.Polynomial_Factorial"
"HOL-Number_Theory.Eratosthenes"
"HOL-Examples.Records"
"HOL-Examples.Gauss_Numbers"
begin

text ‹Drop technical stuff from \<^theory>‹HOL.Quickcheck_Narrowing› which is tailored towards Haskell›

setup ‹
fn thy =>
let
val tycos = Sign.logical_types thy;
val consts = map_filter (try (curry (Axclass.param_of_inst thy)
\<^const_name>‹Quickcheck_Narrowing.partial_term_of›)) tycos;
in fold Code.declare_unimplemented_global consts thy end
›

text ‹Simple example for the predicate compiler.›

inductive sublist :: "'a list ⇒ 'a list ⇒ bool"
where
empty: "sublist [] xs"
| drop: "sublist ys xs ⟹ sublist ys (x # xs)"
| take: "sublist ys xs ⟹ sublist (x # ys) (x # xs)"

code_pred sublist .

text ‹Avoid popular infix.›

code_reserved SML upto

text ‹Explicit check in ‹OCaml› for correct precedence of let expressions in list expressions›

definition funny_list :: "bool list"
where
"funny_list = [let b = True in b, False]"

definition funny_list' :: "bool list"
where
"funny_list' = funny_list"

lemma [code]:
"funny_list' = [True, False]"

definition check_list :: unit
where
"check_list = (if funny_list = funny_list' then () else undefined)"

text ‹Explicit check in ‹Scala› for correct bracketing of abstractions›

definition funny_funs :: "(bool ⇒ bool) list ⇒ (bool ⇒ bool) list"
where
"funny_funs fs = (λx. x ∨ True) # (λx. x ∨ False) # fs"

text ‹Explicit checks for strings etc.›

definition ‹hello = ''Hello, world!''›

definition ‹hello2 = String.explode (String.implode hello)›

definition ‹which_hello ⟷ hello ≤ hello2›

end
```