doc-src/Exercises/2001/a3/Trie3.thy
author kleing
Mon, 29 Dec 2003 06:49:26 +0100
changeset 14333 14f29eb097a3
parent 13739 f5d0a66c8124
permissions -rw-r--r--
\<^bsub> .. \<^esub>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13739
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     1
(*<*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     2
theory Trie3 = Main:
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     3
(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     4
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     5
text {* Instead of association lists we can also use partial functions
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     6
that map letters to subtrees. Partiality can be modelled with the help
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     7
of type @{typ "'a option"}: if @{term f} is a function of type
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     8
\mbox{@{typ "'a \<Rightarrow> 'b option"}}, set @{term "f a = Some b"}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     9
if @{term a} should be mapped to some @{term b} and set @{term "f a =
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    10
None"} otherwise.  *}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    11
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    12
datatype ('a, 'v) trie = Trie  "'v option" "'a \<Rightarrow> ('a,'v) trie option";
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    13
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    14
text{* Modify the definitions of @{term lookup} and @{term modify}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    15
accordingly and show the same correctness theorem as above. *}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    16
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    17
(*<*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    18
end;
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    19
(*>*)