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

Error in type of member in documentation #1685

Open
kfisler opened this issue Feb 20, 2023 · 9 comments
Open

Error in type of member in documentation #1685

kfisler opened this issue Feb 20, 2023 · 9 comments

Comments

@kfisler
Copy link
Contributor

kfisler commented Feb 20, 2023

The type given for member in the docs constrains the element to search for to be of the same type that is in the list, rather than Any, which works in practice.

https://www.pyret.org/docs/latest/lists.html#%28part._lists_member%29

@blerner
Copy link
Member

blerner commented Feb 20, 2023

Wasn't that deliberate, though? After all if the types aren't the same, the value can't possibly be in the list. The implementation can't check at runtime that the 'a types are the same (since we can't check parametric type variables anyway), but if the static type system can rule out the program as being type-invalid, then we thought that was a teachable moment of "oh duh, we don't need to run .member here at all!"

@kfisler
Copy link
Contributor Author

kfisler commented Feb 20, 2023

That's fine. I certainly appreciate this type-checking argument. It just isn't consistent with what we can run

@shriram
Copy link
Member

shriram commented Feb 21, 2023

@kfisler are you arguing that the docs should change or the implementation should change? And: how?

@kfisler
Copy link
Contributor Author

kfisler commented Feb 21, 2023

I don't know what the implementation is. All I know is that I can call [list:1, 2, 3].member("a"), getting false as expected. The documentation appears inconsistent with my ability to make that call to a reader who isn't thinking about static typechecking (which was the source of the typo report that we got on DCIC around this issue, since DCIC says that the contract on member is List<A>, Any -> Boolean.

Personally, the Any type makes sense to me here, but you've all thought about the implementation implications

@blerner
Copy link
Member

blerner commented Feb 21, 2023

But there are always going to be things that a dynamically typed language will permit that a statically typed one wont, simple as link(1, link(true, link("hi", empty))). That doesn't mean we're going to change the type of lists to be heterogeneous!

@shriram
Copy link
Member

shriram commented Feb 21, 2023 via email

@jpolitz
Copy link
Member

jpolitz commented Feb 21, 2023 via email

@kfisler
Copy link
Contributor Author

kfisler commented Feb 21, 2023 via email

@shriram
Copy link
Member

shriram commented Feb 21, 2023

I'm not sure whether you [@jpolitz] are disagreeing with me or think I'm disagreeing with you or what.

My position:

  • We cannot afford to check this dynamically. [NB: We still check the list tag, not its contents.]
  • We can afford to check it in statically-typed Pyret.
  • But the published contract is still misleading. I do not like the Any there.

So my proposal is that the documentation say it's a homogenously-typed list, but leave the enforcement to statics, maybe an expensive dynamic mode (currently non-existent), or vibes (current dynamic mode).

DCIC should pretend like this is type-enforced. After all, it is enforced in current Anchor: [list: 1, 2, 3].member("a") gives a static type error.

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

No branches or pull requests

4 participants