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 comparable typevar constraints #390

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Add comparable typevar constraints #390

wants to merge 15 commits into from

Conversation

ghallak
Copy link
Contributor

@ghallak ghallak commented Jun 14, 2022

Fixes: #229

docs/sophia_features.md Outdated Show resolved Hide resolved
src/aeso_ast_infer_types.erl Outdated Show resolved Hide resolved
@@ -2016,7 +2048,8 @@ next_count() ->

ets_tables() ->
[options, type_vars, constraints, freshen_tvars, type_errors,
defined_contracts, warnings, function_calls, all_functions].
defined_contracts, warnings, function_calls, all_functions,
ord_constraint_types].
Copy link
Member

Choose a reason for hiding this comment

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

Where are eq_constraint_types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no such table as I didn't find a use for it, if all ids are comparable by equality, what should go in that table?

Copy link
Member

Choose a reason for hiding this comment

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

I don't get why there is a need for a table for ord but not for eq. Would you explain why one is needed and the other is not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since all types of the form {id, _, Id} are compared by eq, there is no need to store all of them in a table, but not all types of the above form are compared by ord so I only need to store that.

So checking if {id, _, "int"} is comparable by ord will only succeed because "int" is in the table ord_constraint_types, but checking if any other type of the form {id, _, Id} is comparable by eq will always succeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check this commit that made address comparable by ord fc28759.

@@ -0,0 +1,169 @@
contract A = entrypoint init() = ()

main contract C =
Copy link
Member

Choose a reason for hiding this comment

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

Please write tests for type inference:

function f(x) = x == x // PASS

function g() = f(g) // FAIL

docs/sophia_features.md Outdated Show resolved Hide resolved
src/aeso_ast_infer_types.erl Show resolved Hide resolved
@@ -29,9 +29,11 @@ namespace List =
[] => abort("drop_last_unsafe: list empty")


function contains(e : 'a, l : list('a)) = switch(l)
Copy link
Member

Choose a reason for hiding this comment

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

Please add versions of insert_by and sort (and possibly others) that instead of taking a comparison lambda, rely on the constraints

Copy link
Member

Choose a reason for hiding this comment

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

Remember that you actually can reuse the existing definitions by just applying them with a lambda

Copy link
Member

@radrow radrow left a comment

Choose a reason for hiding this comment

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

Update fold in aeso_syntax_utils

@ghallak ghallak self-assigned this Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add comparable typevar constraints
2 participants