-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Domain keys in map #14478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Domain keys in map #14478
Conversation
- Introduced tests for union, intersection, and difference operations involving domain key types. - Validated subtype relationships and intersection results for maps with domain keys. - Enhanced map fetch and delete functionalities to handle domain key types. - Ensured correct behavior of dynamic types with domain keys in various scenarios.
…n_map_with_default to map_with_default and implement map_update functionality
I will lock this issue for now because of spam, will reopen once I have feedback. :( |
lib/elixir/lib/module/types/descr.ex
Outdated
|
||
defguardp is_optional_static(map) | ||
when is_map(map) and is_map_key(map, :optional) | ||
|
||
defp map_new(tag, fields = %{}), do: [{tag, fields, []}] | ||
defp map_new(tag, fields = %{}, domains = %{}), do: [{{tag, domains}, fields, []}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should simply have the tag be either: :open, :closed, or domains
. If you have a map as the tag, then it has domains key. If an open map, then we expand everything, as done in map_with_default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's possible to do so, the benefit of keeping them is just so we can represent {:open, domains} without putting a top type in all the undefined domains. But it does not give us much more.
This allows maps to encode domain keys, from paper https://www.irif.fr/~gc/papers/icfp23.pdf
For example, we can now express the type
%{a: integer(), b: float(), atom() => tuple()}
of maps that have keys:a
and:b
and any other atom key mapping to a tuple.Those are created by adding {{:domain_key, :atom}, type} pairs to constructors open_map or closed_map.
This introduces new operators:
map[key]
where key is some expression of some typeMap.put(map, key, type)
(not called map_put because the name is already used for adding a single key to a map. The difference here is that,key
being a type, we are not sure which key is being added).Both operators handle singleton atoms exactly. See the following tests:
Notes:
map_check_domain_keys(tag, neg_tag)
is very long to treat all the different cases optimally. It could be shortened to a single loop on all the possible domains, with default values.