17456
|
1 |
(* Title: CCL/ex/List.thy
|
0
|
2 |
ID: $Id$
|
1474
|
3 |
Author: Martin Coen, Cambridge University Computer Laboratory
|
0
|
4 |
Copyright 1993 University of Cambridge
|
|
5 |
*)
|
|
6 |
|
17456
|
7 |
header {* Programs defined over lists *}
|
|
8 |
|
|
9 |
theory List
|
|
10 |
imports Nat
|
|
11 |
begin
|
0
|
12 |
|
|
13 |
consts
|
|
14 |
map :: "[i=>i,i]=>i"
|
|
15 |
"o" :: "[i=>i,i=>i]=>i=>i" (infixr 55)
|
|
16 |
"@" :: "[i,i]=>i" (infixr 55)
|
|
17 |
mem :: "[i,i]=>i" (infixr 55)
|
|
18 |
filter :: "[i,i]=>i"
|
|
19 |
flat :: "i=>i"
|
|
20 |
partition :: "[i,i]=>i"
|
|
21 |
insert :: "[i,i,i]=>i"
|
|
22 |
isort :: "i=>i"
|
|
23 |
qsort :: "i=>i"
|
|
24 |
|
17456
|
25 |
axioms
|
0
|
26 |
|
17456
|
27 |
map_def: "map(f,l) == lrec(l,[],%x xs g. f(x)$g)"
|
|
28 |
comp_def: "f o g == (%x. f(g(x)))"
|
|
29 |
append_def: "l @ m == lrec(l,m,%x xs g. x$g)"
|
|
30 |
mem_def: "a mem l == lrec(l,false,%h t g. if eq(a,h) then true else g)"
|
|
31 |
filter_def: "filter(f,l) == lrec(l,[],%x xs g. if f`x then x$g else g)"
|
|
32 |
flat_def: "flat(l) == lrec(l,[],%h t g. h @ g)"
|
0
|
33 |
|
17456
|
34 |
insert_def: "insert(f,a,l) == lrec(l,a$[],%h t g. if f`a`h then a$h$t else h$g)"
|
|
35 |
isort_def: "isort(f) == lam l. lrec(l,[],%h t g. insert(f,h,g))"
|
0
|
36 |
|
17456
|
37 |
partition_def:
|
1149
|
38 |
"partition(f,l) == letrec part l a b be lcase(l,<a,b>,%x xs.
|
17456
|
39 |
if f`x then part(xs,x$a,b) else part(xs,a,x$b))
|
1149
|
40 |
in part(l,[],[])"
|
17456
|
41 |
qsort_def: "qsort(f) == lam l. letrec qsortx l be lcase(l,[],%h t.
|
|
42 |
let p be partition(f`h,t)
|
|
43 |
in split(p,%x y. qsortx(x) @ h$qsortx(y)))
|
1149
|
44 |
in qsortx(l)"
|
0
|
45 |
|
17456
|
46 |
ML {* use_legacy_bindings (the_context ()) *}
|
|
47 |
|
0
|
48 |
end
|