Skip to content
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

Type annotations: Order of T and E #7

Closed
dbrgn opened this issue Nov 30, 2017 · 4 comments · Fixed by #8
Closed

Type annotations: Order of T and E #7

dbrgn opened this issue Nov 30, 2017 · 4 comments · Fixed by #8

Comments

@dbrgn
Copy link
Member

dbrgn commented Nov 30, 2017

In Rust, the Result type is defined as Result<T, E> (success case first). In Haskell, it's Either ConnError a and in Elm it's Result error value (error case first). On the other hand OCaml and F# also put the success case first.

When #4 was merged, I did not notice that the type annotation chosen was Generic[E, T]. In general I'm fine with the other order, but since we clearly state that the library is inspired by Rust, I wonder if we should switch the order while we still can. Version 0.3.0 is already released so it might break some people's code, but we're not yet at 1.0, so I think it might be fine.

It's a trivial difference, but I fear that people might get confused with [E, T] when expecting an API similar to Rust and will mix up the order of the type parameters. What do you think, @tyehle?

@dbrgn dbrgn added the question label Nov 30, 2017
@tyehle
Copy link
Contributor

tyehle commented Nov 30, 2017

I agree. Changing the order seems like the right thing to do. When I wrote that I wasn't aware the order was different in Rust than Haskell.

@snorfalorpagus
Copy link
Contributor

Does this have any implication for existing code that has been written one way or another? I had assumed the order was [T, E] and mypy has never complained.

@dbrgn
Copy link
Member Author

dbrgn commented Jun 19, 2018

It only matters if you actually do something with the success or error case that does not comply with the type.

If your result type is Result<str, List[int]> and you call len(...) on the value then that will work with both the success and the error case without mypy complaining.

@dbrgn dbrgn added this to the 0.5.0 milestone Feb 17, 2020
@dbrgn dbrgn closed this as completed in #8 Feb 23, 2020
dbrgn added a commit that referenced this issue Feb 23, 2020
 Change order of generic Result types to [T, E]. Fixes #7.
@dbrgn
Copy link
Member Author

dbrgn commented Feb 23, 2020

#8 is merged, testing the version on master is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants