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

Remove type based duplicates #745

Merged
merged 18 commits into from
Jul 23, 2024

Conversation

vsbogd
Copy link
Collaborator

@vsbogd vsbogd commented Jul 23, 2024

Fixes #235. Type checking behavior is changed (see tests c1_, d2_ and d5_. In particular for the case like:

(: f (-> $t Number))
(f (+ 5 "S"))

previous behavior was to return the most inner type error, i.e. (Error "S" BadType), now interpreter returns less inner type error, i.e. (Error (+ 5 "S") BadType). I am not sure whether one should be preferred over another.

vsbogd added 12 commits July 23, 2024 10:18
collapse_bind returned nothing if last non-deterministic branch returned
empty result. This commit fixes the behavior by adding a dummy non-empty
branch which returns result not included into collapse_bind results.
Interpreter and type-checking code treat calls of the functions without
type declared differently. Type checker represents this call as a tuple
type. But interpreter calls it thus effectively treating it as
%Undefined% type. This commit adds %Undefined% to the list of types for
tuples which are not function calls removing the difference.
Before this logic got the types of the function and tried to apply each to
the parameter's types. Thus each time effectively evaluating the
function result with the given function type. It leads to the
duplication of the function results when the same function has few
different type signatures (non-deterministic type). This commit changes
behavior. New behavior is filtering list of the function type by
checking if type is applicable to the parameter's types first. Then get
any type from the list and call the function using this type.
@vsbogd vsbogd marked this pull request as ready for review July 23, 2024 07:30
@vsbogd vsbogd closed this Jul 23, 2024
@vsbogd vsbogd reopened this Jul 23, 2024
@vsbogd vsbogd requested a review from Necr0x0Der July 23, 2024 09:10
@vsbogd
Copy link
Collaborator Author

vsbogd commented Jul 23, 2024

This also blocks #668 from merging.

!(assertEqualToResult
(f (+ 5 "S"))
((Error "S" BadType)))
; TODO: This test has different behavior in old_interpreter and minimal interpreter.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I like the new behavior better

!(assertEqualToResult
(get-type (fmap (curry-a + 2) (UntypedC (Null) 5)))
())
; Two examples below are type-checked successfully because, (UntypedC "5")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I agree. The type of (UntypedC "5") should be reducible to %Undefined% meaning that the whole expression can type-check. I'd add "FIXME" or "TODO", because we may need to revisit these tests and uncomment their updated versions

@vsbogd vsbogd merged commit 9c126b1 into trueagi-io:main Jul 23, 2024
2 checks passed
@vsbogd vsbogd deleted the remove-type-based-duplicates-2 branch September 16, 2024 10:15
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.

Multiple type definitions cause multiple results
2 participants