Munksgaard / session-types

MIT License
549 stars 21 forks source link

Dont use Result for `offer` #14

Closed Munksgaard closed 9 years ago

Munksgaard commented 9 years ago

Following a discussion with @Manishearth, I've become convinced that we shouldn't abuse Result in offer. Instead we should implement our own Either or Branch type.

@laumann: Agree?

laumann commented 9 years ago

Yes

laumann commented 9 years ago

Copy of discussion from elsewhere:

@Manishearth: In Rust the tendency is to create new types for stuff like this; being a well known type Result has a connotation too, which isn't satisfied here. If a method returns a result people will tend to assume it's for error handling (and often magick it away via unwrap() or try! which we don't want -- each branch should be handled)

@laumann: I guess it would be a matter of substituting Result for an enum like

enum Branch<L, R> {
    Left(L),
    Right(R)
}

and match like

match c.offer() {
    Branch::Left(c) => { /* Left branch */ }
    Branch::Right(c) => { /* Right branch */ }
}

@Manishearth: Yep, more or less. Publicly exporting Branch::* makes it less noisy too.

We could change sel1()/sel2() with left() and right() too

@laumann: The names sel1 and sel2 are from the Haskell paper from which we've borrowed the structure and all the names. But I like left() and right() more - personally I find it more intuitive.