Skip to content
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

Add e.eq(a, b, exact: bool) #8

Open
PgBiel opened this issue Jan 15, 2025 · 0 comments
Open

Add e.eq(a, b, exact: bool) #8

PgBiel opened this issue Jan 15, 2025 · 0 comments
Labels
data functions Related to data retrieval functions feature Request for a new feature

Comments

@PgBiel
Copy link
Owner

PgBiel commented Jan 15, 2025

Recursively check for equality, avoiding pitfalls where eid(a) == eid(b) but func(a) != func(b) for elements (and similarly for custom types with tid(a) == tid(b))

With the exact parameter, we can also check for strict equality, which would allow us to properly implement dictionary and array literals (right now exact(...) on them doesn't work as expected).

Some ideas:

  • exact: false impl:

    • If a == b works, return true
    • If both are custom types with the same tid, then apply eq(a.field, b.field, exact: exact) for each field recursively
    • If both are custom elements with the same eid, then apply eq(a.field, b.field, exact: exact) for each field recursively
    • If both are dictionaries, apply eq(a.at(k), b.at(k), exact: exact) recursively (fail early if there is k in a which is not in b or vice-versa)
    • If both are arrays (fail early if they have different lengths), apply eq(a.at(i), b.at(i), exact: exact) recursively
    • Otherwise false
    • Possible optimization: Elements and types store whether all of their fields are "simple" to compare (fields(a) == fields(b) is enough), e.g. not structured (not content, dict or array)
  • exact: true impl:

    • If type(a) != type(b) return false early
    • If a == b and a, b are both "simple" types (not dictionary / array / content), then return true
    • Otherwise do the rest of the procedure above
@PgBiel PgBiel added feature Request for a new feature data functions Related to data retrieval functions labels Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data functions Related to data retrieval functions feature Request for a new feature
Projects
None yet
Development

No branches or pull requests

1 participant