-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Set-theoretic tuple types #13576
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
Set-theoretic tuple types #13576
Conversation
catch | ||
:discard_negative -> tuple_empty?(tag, fields, negs) | ||
end | ||
end |
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.
Can we rewrite it to a non-raising versaion like the map one is currently implemented? :)
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.
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! I see this now thank you :)
@@ -672,6 +686,19 @@ defmodule Module.Types.Descr do | |||
end | |||
end | |||
|
|||
defp remove_optional(type) do |
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.
Let's use the existing pop_optional instead!
defp tuple_union(left, right), do: map_union(left, right) | ||
|
||
# Same as map_fetch, only the tuple descr field is accessed | ||
def tuple_fetch(%{} = descr, key) do |
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.
def tuple_fetch(%{} = descr, key) do | |
def tuple_fetch(%{} = descr, key) when is_integer(key) do |
for {neg_index, neg_type} <- neg_fields, not is_map_key(fields, neg_index) do | ||
cond do | ||
# This index is not in the closed positive tuple, so there is no value in common | ||
# Tthere are no explicit optional types in tuples |
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.
# Tthere are no explicit optional types in tuples | |
# There are no explicit optional types in tuples |
Closing in favor of #13752. |
Adds to the Descr tuple types
{:ok, binary(), integer()}
and open tuple types{atom(), boolean(), ...}
which represent every tuple of at least two elements that are an atom and a boolean.Tuples are encoded as map records, where the keys are the indices. E.g., type
{integer(), atom()}
is encoded as type%{0 => integer(), 1 => atom()}
and{atom(), boolean(), ...}
is encoded as the open map%{..., 0 => atom(), 1 => boolean()}
.Emptiness checking is slightly modified to account for the fact that tuple types do not admit explicit optional indices.