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

Deprecate auto? #304

Open
thumphries opened this issue May 17, 2018 · 5 comments
Open

Deprecate auto? #304

thumphries opened this issue May 17, 2018 · 5 comments

Comments

@thumphries
Copy link

thumphries commented May 17, 2018

Haven't really thought this through for more than a minute, but wondering if there's any interest in eventually deprecating auto in favour of more concrete readers.

It's been a reliable source of bugs for me / teams I've worked on, since someone inevitably ends up using auto for a string type or a newtyped string/integral. These tend to appear both when writing initial parsers and when changing code a module or two away, in the same way show tends to create subtle non-local bugs when refactoring.

Would involve adding integralOption / fractionalOption for the cases where you might actually want Read, then deprecating auto. Users who want to keep using custom parsers can use maybeReader / eitherReader so their intent is made clear in the code.

@HuwCampbell
Copy link
Collaborator

I'm not super opposed to doing this.

You're right, Read is terrible (and actually doesn't work very well on the command line for most things, due to quoting, Haskell's capitalisation of constructors, and shell expansion primitives). But I do need to balance ease of use and backwards compatibility as well.

integral and fractional would probably cover most use cases where auto currently works cleanly. Are there actually any more?

@thumphries
Copy link
Author

thumphries commented Jun 1, 2018 via email

@quasicomputational
Copy link

quasicomputational commented Jun 4, 2018

auto is also good when you're taking an enum-like argument, as dhall-to-cabal does with --print-type. I'd like to replace it with something better, that isn't Read-based and comes with out-of-the-box completion and listing of valid values, which (a) probably means generics, and (b) doesn't exist today.

@paulyoung
Copy link

@thumphries pointed out that one can write a monomorphic reader in the meantime, e.g.

import Options.Applicative (ReadM, maybeReader)
import Safe (readMay)

int :: ReadM Int
int = maybeReader readMaybe

@georgefst
Copy link

A compromise here might be for the docs to just encourage people to always use an explicit type application with auto.

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

No branches or pull requests

5 participants