Skip to content

Add comparable typevar constraints#390

Open
ghallak wants to merge 15 commits intomasterfrom
ghallak/229
Open

Add comparable typevar constraints#390
ghallak wants to merge 15 commits intomasterfrom
ghallak/229

Conversation

@ghallak
Copy link
Copy Markdown
Member

@ghallak ghallak commented Jun 14, 2022

Fixes: #229

@ghallak ghallak requested a review from radrow June 14, 2022 14:57
Comment thread docs/sophia_features.md Outdated
Comment thread src/aeso_ast_infer_types.erl Outdated
[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
Copy Markdown
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
Copy Markdown
Member 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
Copy Markdown
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
Copy Markdown
Member 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
Copy Markdown
Member 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
Copy Markdown
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

Comment thread docs/sophia_features.md Outdated
Comment thread src/aeso_ast_infer_types.erl
Comment thread priv/stdlib/List.aes
[] => abort("drop_last_unsafe: list empty")


function contains(e : 'a, l : list('a)) = switch(l)
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.

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

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.

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

Copy link
Copy Markdown
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