| author | haftmann |
| Wed, 22 Apr 2009 19:09:19 +0200 | |
| changeset 30959 | 458e55fd0a33 |
| parent 30953 | d5f5ab29d769 |
| child 30972 | 5b65835ccc92 |
| permissions | -rw-r--r-- |
|
30374
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
1 |
theory Predicate_Compile |
| 30810 | 2 |
imports Complex_Main Code_Index Lattice_Syntax |
|
30374
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
3 |
uses "predicate_compile.ML" |
|
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
4 |
begin |
|
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
5 |
|
|
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
6 |
setup {* Predicate_Compile.setup *}
|
|
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
7 |
|
|
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
8 |
primrec "next" :: "('a Predicate.pred \<Rightarrow> ('a \<times> 'a Predicate.pred) option)
|
|
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
9 |
\<Rightarrow> 'a Predicate.seq \<Rightarrow> ('a \<times> 'a Predicate.pred) option" where
|
|
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
10 |
"next yield Predicate.Empty = None" |
|
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
11 |
| "next yield (Predicate.Insert x P) = Some (x, P)" |
|
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
12 |
| "next yield (Predicate.Join P xq) = (case yield P |
|
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
13 |
of None \<Rightarrow> next yield xq | Some (x, Q) \<Rightarrow> Some (x, Predicate.Seq (\<lambda>_. Predicate.Join Q xq)))" |
|
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
14 |
|
| 30812 | 15 |
fun anamorph :: "('b \<Rightarrow> ('a \<times> 'b) option) \<Rightarrow> index \<Rightarrow> 'b \<Rightarrow> 'a list \<times> 'b" where
|
16 |
"anamorph f k x = (if k = 0 then ([], x) |
|
17 |
else case f x of None \<Rightarrow> ([], x) | Some (v, y) \<Rightarrow> let (vs, z) = anamorph f (k - 1) y in (v # vs, z))" |
|
| 30810 | 18 |
|
19 |
ML {*
|
|
| 30953 | 20 |
structure Predicate = |
21 |
struct |
|
22 |
||
23 |
open Predicate; |
|
24 |
||
25 |
fun yield (Predicate.Seq f) = @{code next} yield (f ());
|
|
26 |
||
27 |
fun yieldn k = @{code anamorph} yield k;
|
|
28 |
||
29 |
end; |
|
| 30810 | 30 |
*} |
|
30374
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
31 |
|
|
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
32 |
end |