Commit c71fb84b authored by Fumiaki Kinoshita's avatar Fumiaki Kinoshita 💬 Committed by Herbert Valerio Riedel
Browse files

Add Eq, Ord, Show, and Read instances for Const

As suggested in

https://www.haskell.org/pipermail/libraries/2013-October/021531.html

this adds the following instances

 - `Show a => Show (Const a b)`
 - `Read a => Read (Const a b)`
 - `Eq a   => Eq   (Const a b)`
 - `Ord a  => Ord  (Const a b)`

The Read/Show instances are defined in such a way as if `Const` was defined
without record-syntax (i.e. as `newtype Const a b = Const a`)

Addresses #9984

Reviewed By: ekmett

Differential Revision: https://phabricator.haskell.org/D619
parent c823b73c
......@@ -61,11 +61,19 @@ import Data.Functor ((<$>))
import GHC.Base
import GHC.Generics
import GHC.List (repeat, zipWith)
import GHC.Read (Read)
import GHC.Show (Show)
import GHC.Read (Read(readsPrec), readParen, lex)
import GHC.Show (Show(showsPrec), showParen, showString)
newtype Const a b = Const { getConst :: a }
deriving (Generic, Generic1, Monoid)
deriving (Generic, Generic1, Monoid, Eq, Ord)
instance Read a => Read (Const a b) where
readsPrec d = readParen (d > 10)
$ \r -> [(Const x,t) | ("Const", s) <- lex r, (x, t) <- readsPrec 11 s]
instance Show a => Show (Const a b) where
showsPrec d (Const x) = showParen (d > 10) $
showString "Const " . showsPrec 11 x
instance Foldable (Const m) where
foldMap _ _ = mempty
......
......@@ -176,7 +176,8 @@
* There are now `Foldable` and `Traversable` instances for `Either a`,
`Const r`, and `(,) a`.
* There is now a `Monoid`, `Generic`, and `Generic1` instance for `Const`.
* There are now `Show`, `Read`, `Eq`, `Ord`, `Monoid`, `Generic`, and
`Generic1` instances for `Const`.
* There is now a `Data` instance for `Data.Version`.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment