| 43158 |      1 | (* Author: Tobias Nipkow *)
 | 
|  |      2 | 
 | 
|  |      3 | theory Util imports Main
 | 
|  |      4 | begin
 | 
|  |      5 | 
 | 
|  |      6 | subsection "Show sets of variables as lists"
 | 
|  |      7 | 
 | 
|  |      8 | text {* Sets are functions and are not displayed by element if
 | 
|  |      9 | computed as values: *}
 | 
|  |     10 | value "{''x'', ''y''}"
 | 
|  |     11 | 
 | 
|  |     12 | text {* Lists do not have this problem *}
 | 
|  |     13 | value "[''x'', ''y'']"
 | 
|  |     14 | 
 | 
|  |     15 | text {* We define a function @{text show} that converts a set of
 | 
|  |     16 |   variable names into a list. To keep things simple, we rely on
 | 
|  |     17 |   the convention that we only use single letter names.
 | 
|  |     18 | *}
 | 
|  |     19 | definition 
 | 
|  |     20 |   letters :: "string list" where
 | 
|  |     21 |   "letters = map (\<lambda>c. [c]) chars"
 | 
|  |     22 | 
 | 
|  |     23 | definition 
 | 
|  |     24 |   "show" :: "string set \<Rightarrow> string list" where
 | 
|  |     25 |   "show S = filter S letters" 
 | 
|  |     26 | 
 | 
|  |     27 | value "show {''x'', ''z''}"
 | 
|  |     28 | 
 | 
|  |     29 | end
 |