-
Notifications
You must be signed in to change notification settings - Fork 660
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
Typestate-oriented programming #3591
Comments
@olleharstedt I'm wondering if [1] was the intended link, because the article there seems to have more to do with marking interpretations of primitive types, rather than marking states. |
@andyg0808 It was intended, since phantom types can simulate typestate in some settings. |
Psalm seems to already have typestate related features, as shown here: #1255 Related to array_shift: /** @var array{string, int} */
$arr = ["foo", 1];
array_shift($arr); // Modifies the type Seems like this happens in method NB: Basically the method |
Psalm already handles closing file handlers via the |
I found these snippets: https://psalm.dev/r/2737e2dc70<?php
$fp = tmpfile();
if ($fp) {
fclose($fp);
fwrite($fp, "hello");
}
|
I don't plan to add any annotations to change state beyond existing |
@muglug Do you plan to do something with alias tracking? E.g. to fix |
Did you guys discuss typestate-oriented programming anything?
Building on article [1], it would allow you to "tag" types and resources, like so:
See [2] for more details about this paradigm. It corresponds loosely to what in functional programming is done with linear (or affine) types.
[1] http://marcosh.github.io/post/2020/05/26/phantom-types-in-php.html
[2] https://www.cs.cmu.edu/%7Ejssunshi/pubs/onward2009-state.pdf
The text was updated successfully, but these errors were encountered: