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

Type checking doesn't work for tuples. #669

Open
vsbogd opened this issue Apr 17, 2024 · 2 comments
Open

Type checking doesn't work for tuples. #669

vsbogd opened this issue Apr 17, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@vsbogd
Copy link
Collaborator

vsbogd commented Apr 17, 2024

Describe the bug

Type checking doesn't work for tuples.

To Reproduce

Run the following MeTTa code:

(: (a b) (C D))

(: foo (-> (A B) %Undefined%))
(= (foo $x) succ)

!(foo (a b))

Expected behavior

Type error: (Error (a b) BadType)

Actual behavior

No type error: succ

@vsbogd vsbogd added the bug Something isn't working label Apr 17, 2024
@vsbogd vsbogd self-assigned this Apr 17, 2024
@vsbogd
Copy link
Collaborator Author

vsbogd commented Apr 17, 2024

Not that straightforward because in the following example:

(: a T)
(: foo (-> T T))
(= (foo $x) $x)
(= (bar $x) $x)
!(foo (bar a))

bar has no type and (bar a) interpreted as a tuple. As a consequence the type of (bar a) is (%Undefined% T) which is not unified with T required by foo. Thus relaxed type-checking allows using untyped functions in many examples.

For example recursive fact definition also fails with tuple type-checking enabled:

(= (fact $n) (if (== $n 0) 1 (* (fact (- $n 1)) $n)))
!(assertEqual (fact 5) 120)

@vsbogd
Copy link
Collaborator Author

vsbogd commented Apr 18, 2024

We could check alternative interpretations:

  • interpret tuple as a function call
  • interpret tuple as a tuple
    and select ones which don't lead to the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant