Map properties #
This file proves useful properties of canonical list-based maps defined in
Cedar.Data.Map.
Well-formed maps #
Equations
- m.WellFormed = (m = Cedar.Data.Map.make m.toList)
Instances For
In well-formed maps, if there are two pairs with the same key, then they have the same value
If two well-formed maps have equivalent (k,v) sets, then the maps are actually equal
empty, contains, mem, toList, keys, values #
As a crutch to accommodate some pre-existing usage, we provide this theorem. But
TODO in the future we should transition users of this theorem to instead use
public theorems about toList and not have to expose the internals of
Data.Map.
make and mk #
Note that the converse of this is not true:
counterexample xs = [(1, false), (1, true)].
(The property here would not hold for either x = (1, false) or x = (1, true).)
For a limited converse, see mem_list_mem_make below.
This limited converse of make_mem_list_mem requires that the input list is
SortedBy Prod.fst.
find?, findOrErr, and mapOnValues #
Converse is available at in_list_iff_find?_some (requires wf though)
Inverse is available at find?_notmem_keys (requires wf though)
The mpr direction of this does not need the wf precondition and, in fact,
is available separately as find?_mem_toList above
Inverse of find?_mem_toList, except that this requires wf
Two well-formed maps are equal if they have the same find? for every key.
Ideally we wouldn't need this, but it's currently necessary because of the kludgy way
that EntityTag.mk uses Map without relying on its proper constructors
Like List.map_congr, but lifted to Map.mapOnValues
The converse requires the wf precondition, and is available in
findOrErr_ok_iff_in_toList below
The mp direction of this does not need the wf precondition and, in fact,
is available separately as findOrErr_ok_implies_in_toList above
The converse requires the wf precondition, and is available in
find?_some_iff_in_values below
The converse requires the wf precondition, and is available in
findOrErr_ok_iff_in_values below
The mp direction of this does not need the wf precondition and, in fact,
is available separately as find?_some_implies_in_values above
The mp direction of this does not need the wf precondition and, in fact,
is available separately as findOrErr_ok_implies_in_values above
The converse requires the extra precondition that f is injective, and is
available as in_mapOnValues_in_toList
TODO: This is redundant with findOrErr_err_iff_find?_none
Converse of in_toList_in_mapOnValues; requires the extra precondition that f is injective
Slightly different formulation of in_mapOnValues_in_toList
mapMOnValues #
This is not stated in terms of Map.keys because Map.keys produces a Set,
and we want the even stronger property that it not only preserves the key-set,
but also the key-order. (We'll use this to prove mapMOnValues_some_wf.)
Note that the converse is not true:
counterexample m₁ is [(1, false)], m₂ is [(1, false), (2, true)], f is Except.ok
But for a limited converse, see all_ok_implies_mapMOnValues_ok
If a key exists in l₂ but not in l₁,
then Map.make (l₁ ++ l₂) contains that key.
A variant of map_make_append_find_disjoint.
TODO: This is redundant with eq_iff_toList_eq