patterns icon indicating copy to clipboard operation
patterns copied to clipboard

Create typestate.md

Open dgunay opened this issue 5 years ago • 16 comments

Neat pattern for Rust that lets you encode valid/invalid states using the type system.

dgunay avatar Aug 17 '20 09:08 dgunay

It may be more idiomatic to call these "session types", but the article I referenced calls them typestates.

dgunay avatar Aug 19 '20 17:08 dgunay

Is this repo still maintained? @lambda-fairy

dgunay avatar Oct 02 '20 09:10 dgunay

Not really. I think this repo needs someone with time & a vision to make it useful.

lambda-fairy avatar Oct 03 '20 01:10 lambda-fairy

@dgunay Hey, thank you for your contribution! Could you please rebase your branch on master please and link typestate.md in SUMMARY.md? We'll review this PR the upcoming days.

simonsan avatar Jan 01 '21 13:01 simonsan

Status: I wrote the author an email, if he is fine with us taking some of his content and if he could relicense it and state it here somewhere in the repository. Until then we'll need to wait.

simonsan avatar Jan 03 '21 07:01 simonsan

@dgunay Hey, thank you for your contribution! Could you please rebase your branch on master please and link typestate.md in SUMMARY.md? We'll review this PR the upcoming days.

Hi, thank you @simonsan. I am currently unfamiliar with how to do rebases (have never done them yet). I see you merged master into patch-1 - do I still need to do anything?

dgunay avatar Jan 04 '21 03:01 dgunay

git fetch
git rebase origin/master
... edit if there are confilcts
git add ...
git rebase --continue  # do this as many times as needed
git push -f

pickfire avatar Jan 04 '21 03:01 pickfire

@dgunay Hey, thank you for your contribution! Could you please rebase your branch on master please and link typestate.md in SUMMARY.md? We'll review this PR the upcoming days.

Hi, thank you @simonsan. I am currently unfamiliar with how to do rebases (have never done them yet). I see you merged master into patch-1 - do I still need to do anything?

No, I did it, so we let it check with the CI. I've made a small review, maybe you could address the suggestions questions in it for now? ;-) Thanks

simonsan avatar Jan 04 '21 07:01 simonsan

Note that there are other method to have type state, like each one of the state as their own struct, which is more useful when different states have different types. If different states have different types but combined with this technique, there could easily be footguns.

pickfire avatar Jan 06 '21 02:01 pickfire

Note that there are other method to have type state, like each one of the state as their own struct, which is more useful when different states have different types. If different states have different types but combined with this technique, there could easily be footguns.

Do you want to make some suggestions to change. I see a bit of a problem in that this is taken from another author as well. And I struggle a bit to reach the author. He answered me that we could link to his article and I should get back if linking is not an option for relicensing. So I wrote back that just linking the article is probably not the best way, if we want to keep it in the repository. But didn't receive an answer yet. So citation of some stuff might be fine in this regards, but just taking a lot from the article is not, I feel. So we might have to rewrite it nevertheless. Unless the author shows up here and states what he thinks (what he could, as I sent him a link to this PR).

simonsan avatar Jan 06 '21 06:01 simonsan

I mean something like using structs to have types as state. Like from Letter { data: ... } to ClosedLetter to OpenedLetter or something like that, I once read another article like this.

pickfire avatar Jan 11 '21 15:01 pickfire

Something to read https://www.novatec-gmbh.de/en/blog/the-case-for-the-typestate-pattern-introducing-algebraic-data-types/

simonsan avatar Feb 27 '21 00:02 simonsan

I believe we can add something like #227 here and fix that along since it is similar enough? Here it encodes the state as variable but that encodes it as a type (which I think is more preferable).

pickfire avatar Feb 27 '21 06:02 pickfire

Another blogpost: https://www.novatec-gmbh.de/en/blog/the-case-for-the-typestate-pattern-the-typestate-pattern-itself/

simonsan avatar Mar 18 '21 14:03 simonsan

Closing in favour of #249

simonsan avatar Mar 28 '21 16:03 simonsan

Reopening due to change of scope of #249

simonsan avatar Apr 02 '21 19:04 simonsan