Skip to content

Conversation

gldubc
Copy link
Member

@gldubc gldubc commented Oct 21, 2024

Proper list types:

  • list()
  • list(integer()) a (possibly empty) list of integers

Improper lists:

  • list(integer(), atom()) (a list of integers, with an atom at the tail)

A type like list(term(), term() includes both propers lists and improper lists (since term() includes empty_list())

Also includes hd and tl operators, type-safe so using those on lists that may be empty will error

Using tl on a improper list like list(integer(), atom()) will return either a list of integers or an atom().

The addition creates some warning for the compiler on patterns not matching, to be fixed :)

union(dynamic(list_tl_static(dynamic)), list_tl_static(static))

is_dynamic_list and only_list ->
:not_non_empty_list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to :empty_list!

Comment on lines +885 to +891
# Eliminate empty lists from the union TODO
defp list_normalize(dnf), do: dnf
# Enum.filter(dnf, fn {list_type, last_type, negs} ->
# not Enum.any?(negs, fn neg -> subtype?(list_type, neg) end)
# end)
# end
#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Eliminate empty lists from the union TODO
defp list_normalize(dnf), do: dnf
# Enum.filter(dnf, fn {list_type, last_type, negs} ->
# not Enum.any?(negs, fn neg -> subtype?(list_type, neg) end)
# end)
# end
#
# TODO: Eliminate empty lists from the union TODO
defp list_normalize(dnf), do: dnf
# Enum.filter(dnf, fn {list_type, last_type, negs} ->
# not Enum.any?(negs, fn neg -> subtype?(list_type, neg) end)
# end)
# end

def list(_arg), do: %{bitmap: @bit_list}
def non_empty_list(_arg, _tail \\ empty_list()), do: %{bitmap: @bit_non_empty_list}

# TODO: check emptiness here?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check emptiness of what? :)

[to_quoted(list_type), to_quoted(last_type)]
end

if Enum.empty?(negs) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if Enum.empty?(negs) do
if negs == [] do

end
end

def list_to_quoted(dnf) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def list_to_quoted(dnf) do
defp list_to_quoted(dnf) do

@josevalim
Copy link
Member

Merged manually, thank you!

@josevalim josevalim closed this Oct 24, 2024
@gldubc gldubc deleted the list-types branch November 5, 2024 14:41
@gldubc gldubc restored the list-types branch November 5, 2024 14:41
@gldubc gldubc deleted the list-types branch November 5, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants