Skip to content

Preserve left element types in list subtraction - #15808

Open
lukaszsamson wants to merge 1 commit into
elixir-lang:mainfrom
lukaszsamson:ls-list-minus-types
Open

Preserve left element types in list subtraction#15808
lukaszsamson wants to merge 1 commit into
elixir-lang:mainfrom
lukaszsamson:ls-list-minus-types

Conversation

@lukaszsamson

Copy link
Copy Markdown
Contributor

Teach the type system that list -- returns a possibly empty sublist of its left operand while preserving proper-list validation for both operands.

Assisted-by: Codex:GPT-5.6 Sol, Claude Fable 5

Teach the type system that list subtraction returns a possibly-empty sublist of its left operand while preserving proper-list validation for both operands.

Assisted-by: Codex:GPT-5
defp remote_apply(:erlang, :--, _info, [left, right], stack) do
case {list_of(left), list_of(right)} do
{{_, list_of}, {_, _}} ->
result = if list_of, do: list(list_of), else: empty_list()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this the same as left?

@josevalim

josevalim commented Aug 29, 2026

Copy link
Copy Markdown
Member

@lukaszsamson ideally, we don't want to implement most of those, except for:

  1. our type signatures are not expressive enough to type them
  2. the functions are common enough that typing them now justify it
  3. (updated) they are Erlang functions

In that case, I am thinking the type signature of this would be a, list(term()) -> a when a: list(term()), right? And because it is not common, I think we can skip it for now.

@josevalim

Copy link
Copy Markdown
Member

Actually, ignore me, it is an Erlang function, we need to type it anyway. We may have more precise signatures later, but we do need to type it, so the change is good. I updated my list above. Just check my comment in the code!

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