quiet: Generic deriving of Read/Show with no record labels.

[ bsd3, generics, library ] [ Propose Tags ]

Please see the README on GitHub at https://github.com/jacobstanley/quiet#readme


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.2
Change log ChangeLog.md
Dependencies base (>=4.7 && <5) [details]
License BSD-3-Clause
Copyright Copyright (c) 2016-2020
Author Jacob Stanley
Maintainer jacob@stanley.io
Category Generics
Home page https://github.com/jacobstanley/quiet#readme
Bug tracker https://github.com/jacobstanley/quiet/issues
Source repo head: git clone https://github.com/jacobstanley/quiet
Uploaded by JacobStanley at 2020-02-01T13:33:52Z
Distributions LTSHaskell:0.2, NixOS:0.2, Stackage:0.2
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 13653 total (125 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-02-01 [all 1 reports]

Readme for quiet-0.2

[back to package description]

quiet

Generic deriving of Read / Show with no record labels.

Hackage Travis

Often one wants to create a newtype which has a convenient field accessor like unUserId below, but that unfortunately makes the Show instance which is derived overly verbose.

For example:

newtype UserId = UserId { unUserId :: String }
  deriving (Read, Show)
ghci> show (UserId "simon")
UserId {unUserId = "simon"}
ghci> read "UserId {unUserId = \"simon\"}" :: UserId
UserId {unUserId = "simon"}

With DerivingVia Quiet you can have a Show instance which doesn't print the field labels. It will render as if the unUserId accessor wasn't present at all.

newtype UserId = UserId { unUserId :: String }
  deriving (Generic)
  deriving (Read, Show) via (Quiet UserId)
ghci> show (UserId "simon")
UserId "simon"
ghci> read "UserId \"simon\"" :: UserId
UserId "simon"

If you want to derive Read / Show without using DerivingVia then you can use qreadPrec and qshowsPrec directly.

instance Read UserId where readPrec = qreadPrec
instance Show UserId where showsPrec = qshowsPrec