Arity specialized branching constructs - #23
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.
Munksgaard
commented
Sep 2, 2015
We'd definitely want some macros to actually define the different constructs and methods instead of doing it manually. |
Munksgaard
commented
Sep 2, 2015
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
|
Manishearth
commented
Sep 2, 2015
I wonder if we can make this work with tuples? |
Definitely prettier, but we still need the BranchN constructs.
Munksgaard
commented
Sep 2, 2015
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. |
Manishearth
commented
Sep 2, 2015
We could just |
Manishearth
commented
Sep 2, 2015
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. |
Munksgaard
commented
Sep 2, 2015
I actually think I prefer the tupled version over the OfferN version regardless. |
Manishearth
commented
Sep 2, 2015
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 anOfferNwithassociated
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.