[commit: ghc] ghc-7.10: Add Eq, Ord, Show, and Read instances for Const (aaca7bd)
git at git.haskell.org
git at git.haskell.org
Wed Jan 14 19:57:16 UTC 2015
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-7.10
Link : http://ghc.haskell.org/trac/ghc/changeset/aaca7bdfa6202895946ac253a3196c4efa5747b7/ghc
>---------------------------------------------------------------
commit aaca7bdfa6202895946ac253a3196c4efa5747b7
Author: Fumiaki Kinoshita <fumiexcel at gmail.com>
Date: Wed Jan 14 20:41:30 2015 +0900
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
(cherry picked from commit c71fb84b8c9ec9c1e279df8c75ceb8a537801aa1)
>---------------------------------------------------------------
aaca7bdfa6202895946ac253a3196c4efa5747b7
libraries/base/Control/Applicative.hs | 14 +++++++++++---
libraries/base/changelog.md | 3 ++-
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/libraries/base/Control/Applicative.hs b/libraries/base/Control/Applicative.hs
index a0627e4..02062e2 100644
--- a/libraries/base/Control/Applicative.hs
+++ b/libraries/base/Control/Applicative.hs
@@ -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
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 76a6a19..83ae5e4 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -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`.
More information about the ghc-commits
mailing list