问题
So far I can define a map
map_of [(1, 2), (3, 4::int)]
of type
'a => int option
When I try to get the domain of the map:
dom (map_of [(1, 2), (3, 4::int)])
give the error
Wellsortedness error:
Type 'b not of sort enum
Cannot derive subsort relation {equal,numeral} < enum
The examples in Enum.thy only show finite cases, how do you prove the enum property for an infinite type like int or nat?
Update 1: Fixed the syntax and give the exact error message
回答1:
This looks like a problem that occurs when trying to evaluate the expression
dom (map_of [(1, 2), (3, 4::int)])
e.g. using the "value" command.
The reason why this doesn't work is that "map_of" essentially gives you a function and the domain of a function is not in general computable.
Still, you can use your map and carry out proofs:
lemma "dom (map_of [(1, 2), (3, 4::nat)]) = {1, 3}"
by simp
Or, if you'd rather have something computable, then you can just keep using lists of tuples. In Isabelle2016-1, there will be a dedicated "finite map" type too:
theory Scratch
imports "~~/src/HOL/Library/Finite_Map"
begin
value "fmdom' (fmap_of_list [(1, 2), (3, 4::nat)])"
(* prints "{1, 1 + 1 + 1}" *)
来源:https://stackoverflow.com/questions/39399652/what-is-the-syntax-to-use-map-thy