text‹ For convenience, we often want to utilise the same expression syntax for multiple constructs.
This can be achieved using ad-hoc overloading. We create a number of polymorphic constants and then
overload their definitions using appropriate implementations. In order for this to work,
each collection must have its own unique type. Thus we do not use the HOL map type directly,
but rather our own partial function type, for example. ›
consts
― ‹ Empty elements, for example empty set, nil list, 0... ›
uempty :: "'f"
― ‹ Function application, map application, list application... ›
uapply :: "'f ==> 'k ==> 'v"
― ‹ Function update, map update, list update... ›
uupd :: "'f ==> 'k ==> 'v ==> 'f"
― ‹ Domain of maps, lists... ›
udom :: "'f ==> 'a set"
― ‹ Range of maps, lists... ›
uran :: "'f ==> 'b set"
― ‹ Domain restriction ›
udomres :: "'a set ==> 'f ==> 'f"
― ‹ Range restriction ›
uranres :: "'f ==> 'b set ==> 'f"
― ‹ Collection cardinality ›
ucard :: "'f ==> nat"
― ‹ Collection summation ›
usums :: "'f ==> 'a"
― ‹ Construct a collection from a list of entries ›
uentries :: "'k set ==> ('k ==> 'v) ==> 'f"
text‹ We need a function corresponding to function application in order to overload. ›
definition fun_apply :: "('a ==> 'b) ==> ('a ==> 'b)" where"fun_apply f x = f x"
declare fun_apply_def [simp]
definition ffun_entries :: "'k set ==> ('k ==> 'v) ==> ('k, 'v) ffun"where "ffun_entries d f = graph_ffun {(k, f k) | k. k ∈ d}"
text‹ We then set up the overloading for a number of useful constructs for various collections. ›
adhoc_overloading
uempty ⇌0and
uapply ⇌ fun_apply and uapply ⇌ nth and uapply ⇌ pfun_app and
uapply ⇌ ffun_app and
uupd ⇌ pfun_upd and uupd ⇌ ffun_upd and uupd ⇌ list_augment and
udom ⇌Domainand udom ⇌ pdom and udom ⇌ fdom and udom ⇌ seq_dom and
udom ⇌ Range and uran ⇌ pran and uran ⇌ fran and uran ⇌ set and
udomres ⇌ pdom_res and udomres ⇌ fdom_res and
uranres ⇌ pran_res and udomres ⇌ fran_res and
ucard ⇌ card and ucard ⇌ pcard and ucard ⇌ length and
usums ⇌ list_sum and usums ⇌ Sum and usums ⇌ pfun_sum and
uentries ⇌ pfun_entries and uentries ⇌ ffun_entries
translations
― ‹ Pretty printing for adhoc-overloaded constructs › "f(x)a" <= "CONST uapply f x" "domu(f)" <= "CONST udom f" "ranu(f)" <= "CONST uran f" "A ⊲u f" <= "CONST udomres A f" "f ⊳u A" <= "CONST uranres f A" "#u(f)" <= "CONST ucard f" "f(k ↦ v)u" <= "CONST uupd f k v" "0" <= "CONST uempty" ― ‹ We have to do this so we don't see uempty. Is there a better way of printing? ›
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.