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

Consistent type for 'readMaybe' and 'readEither' #286

Closed
chshersh opened this issue May 13, 2020 · 1 comment · Fixed by #296
Closed

Consistent type for 'readMaybe' and 'readEither' #286

chshersh opened this issue May 13, 2020 · 1 comment · Fixed by #296
Assignees
Labels
question Further information is requested

Comments

@chshersh
Copy link
Contributor

chshersh commented May 13, 2020

The two functions are used to parse types with the Read instance from String. However, they have a slightly different type (one is more polymorphic than the other):

  • readMaybe :: Read a => String -> Maybe a
  • readEither :: (ToString a, Read b) => a -> Either Text b

I think this difference in behaviour can be surprising for some users. So I propose to chose one of the following options:

  1. Both work with monomorphic String
  2. Both work with polymorphic ToString

Both approaches have benefits and drawbacks: String is more beginner-friendly and less surprises for relude users, ToString is more flexible and convenient.

My initial thought is that both functions should work with String, and we can have a module like Relude.Extra.Parse/Read/String where we can put more polymorphic functions, including the ones proposed in #161.

@chshersh chshersh added the question Further information is requested label May 13, 2020
@chshersh chshersh added this to the v0.8.0.0: Standard milestone May 13, 2020
@vrom911
Copy link
Member

vrom911 commented May 13, 2020

Nice catch! I also give my vote to the first option. It is less surprising and breaking.

@vrom911 vrom911 changed the title [RFC] Consistent type for 'readMaybe' and 'readEither' Consistent type for 'readMaybe' and 'readEither' May 14, 2020
@vrom911 vrom911 self-assigned this May 14, 2020
chshersh added a commit that referenced this issue May 14, 2020
* [#286] Consistent type for 'readMaybe' and 'readEither'

Resolves #286

* Update CHANGELOG.md

Co-authored-by: Dmitrii Kovanikov <[email protected]>

Co-authored-by: Dmitrii Kovanikov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants