-
Notifications
You must be signed in to change notification settings - Fork 18
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
Question regarding types and their understanding #34
Comments
Let's start from situation when only three types are added:
I also replacing
The reason is that Why I should note here that minimal MeTTa behaviour differs. It returns empty result even for
and after adding type for the
I will look at this difference later. |
Adding two types for
Now for each call of the Usually it is expected that interpreter will cut the branches which has type errors. But in case of your program it doesn't happen because Adding |
I've met some issue (probably it is my misunderstanding of how metta works with typed functions though) when adding types to functions. Here is the code and it works fine. It counts leaves of tree as name states.
Problems starts when I'm trying to add types here. They are not actually needed but I was checking Anatoly's suggestion about influence of types on script's performance. Anyway, I've inserted those lines:
(: List (-> $a Type))
(: Nil (List $a))
(: Cons (-> $a (List $a) (List $a)))
(: count-leaves (-> Number Number))
(: count-leaves (-> (List Number) Number))
After this, strange behavior (at least in my understanding) happened.
Launching
!(count-leaves (list (1 2 3 4)))
gives
[4,4]
, not just4
and launching
!(count-leaves (Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil)))))
gives
[4]
which is correct. But i don't understand how is it possible since(list (1 2 3 4))
and(Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil))))
should be the same. What am i missing?Almost same goes to the tree example:
Though, once again,
(x)
and(Cons (Cons 1 (Cons 2 (Cons 3 Nil))) (Cons 3 (Cons 4 Nil)))
should be the same. Though it is not true. This one works:But this one - not:
It gives:
In case of tree (x) it is probably related to types of List and Cons. So, questions are:
(Cons (Cons 1 (Cons 2 (Cons 3 Nil))) (Cons 3 (Cons 4 Nil)))
as it is it produces an error.!(count-leaves (list (1 2 3 4)))
but not for!(count-leaves (Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil)))))
? Why behavior is different for same (as I understand) input?My opinion is that it can be related to different evaluation sequence with and without types.
Thanks in advance.
The text was updated successfully, but these errors were encountered: