-
Notifications
You must be signed in to change notification settings - Fork 21
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
Arity specialized branching constructs #23
base: master
Are you sure you want to change the base?
Conversation
This is an experiment that introduces arity specialized branching constructs. The idea is to add multiple specialized Offer/Choose constructs according to arity. That way, instead of chaining lots of Offer's and having to do `sel2().sel2().sel2()`, we'd simply have an `OfferN` with associated `sel1()`, `sel2()`, ..., and `selN()` methods. This commit only introduces Offer3 and Choose3 structs, but serves to give us an idea of how our library would end up looking.
We'd definitely want some macros to actually define the different constructs and methods instead of doing it manually. |
Pros:
Cons:
match c.offer() {
Branch3::B1(c) => ...
Branch3::B2(c) => ...
Branch3::B3(c) => ...
}
... If you later change the arity of the branch you have to actually change all of these
|
I wonder if we can make this work with tuples? |
Definitely prettier, but we still need the BranchN constructs.
Good idea, @Manishearth! Check out c936af4. We still need the BranchN structs as far as I can tell, but we get rid of the multitude of OfferN structs. |
We could just |
Oh, but the enums need to be made no matter what. In that case we shouldn't complicate it with tuples and just macro all the things I guess. The macro for this is pretty simple afaict. |
I actually think I prefer the tupled version over the OfferN version regardless. |
SGTM. We can always make OfferN typedefs anyway. |
This is an experiment that introduces arity specialized branching
constructs. It's not meant to be immediately merged, but to serve as a discussion point regarding this alternative library design, and whether it's something we might want.
The idea is to add multiple specialized Offer/Choose constructs
according to arity. That way, instead of chaining lots of Offer's and
having to do
sel2().sel2().sel2()
, we'd simply have anOfferN
withassociated
sel1()
,sel2()
, ..., andselN()
methods.So far I've only introduced Offer3 and Choose3 structs, but they serve to
give us an idea of how the library would end up looking.
Edit: Almost all of the tests and examples will be failing right now, but that's to be expected. Consult the ATM example (examples/atm.rs) to see how it looks from a users perspective.