[commit: ghc] master: Auto-derive a few manually coded Show instances (fdc03a7)
git at git.haskell.org
git at git.haskell.org
Fri Sep 19 09:37:33 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/fdc03a78ab1b3c03e4d1757fca062eaf7a47834a/ghc
>---------------------------------------------------------------
commit fdc03a78ab1b3c03e4d1757fca062eaf7a47834a
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date: Fri Sep 19 10:25:34 2014 +0200
Auto-derive a few manually coded Show instances
In `base`, the instances
instance Show ()
instance Show Bool
instance Show Ordering
instance Show a => Show (Maybe a)
where defined manually, even though we can leverage GHC's auto-deriver
which is perfectly capable by standalone derivation to avoid boiler-plate
code such as this.
Reviewed By: austin
Differential Revision: https://phabricator.haskell.org/D219
>---------------------------------------------------------------
fdc03a78ab1b3c03e4d1757fca062eaf7a47834a
libraries/base/GHC/Show.lhs | 20 ++++----------------
testsuite/tests/perf/compiler/all.T | 2 +-
2 files changed, 5 insertions(+), 17 deletions(-)
diff --git a/libraries/base/GHC/Show.lhs b/libraries/base/GHC/Show.lhs
index 93320ee..2834817 100644
--- a/libraries/base/GHC/Show.lhs
+++ b/libraries/base/GHC/Show.lhs
@@ -179,8 +179,7 @@ appPrec1 = I# 11# -- appPrec + 1
\begin{code}
-instance Show () where
- showsPrec _ () = showString "()"
+deriving instance Show ()
instance Show a => Show [a] where
{-# SPECIALISE instance Show [String] #-}
@@ -188,14 +187,8 @@ instance Show a => Show [a] where
{-# SPECIALISE instance Show [Int] #-}
showsPrec _ = showList
-instance Show Bool where
- showsPrec _ True = showString "True"
- showsPrec _ False = showString "False"
-
-instance Show Ordering where
- showsPrec _ LT = showString "LT"
- showsPrec _ EQ = showString "EQ"
- showsPrec _ GT = showString "GT"
+deriving instance Show Bool
+deriving instance Show Ordering
instance Show Char where
showsPrec _ '\'' = showString "'\\''"
@@ -216,12 +209,7 @@ showWord w# cs
c# ->
showWord (w# `quotWord#` 10##) (C# c# : cs)
-instance Show a => Show (Maybe a) where
- showsPrec _p Nothing s = showString "Nothing" s
- showsPrec p (Just x) s
- = (showParen (p > appPrec) $
- showString "Just " .
- showsPrec appPrec1 x) s
+deriving instance Show a => Show (Maybe a)
\end{code}
diff --git a/testsuite/tests/perf/compiler/all.T b/testsuite/tests/perf/compiler/all.T
index be09a1c..96e2e11 100644
--- a/testsuite/tests/perf/compiler/all.T
+++ b/testsuite/tests/perf/compiler/all.T
@@ -229,7 +229,7 @@ test('T3064',
# expected value: 14 (x86/Linux 28-06-2012):
# 2013-11-13: 18 (x86/Windows, 64bit machine)
# 2014-01-22: 23 (x86/Linux)
- (wordsize(64), 52, 20)]),
+ (wordsize(64), 42, 20)]),
# (amd64/Linux): 18
# (amd64/Linux) 2012-02-07: 26
# (amd64/Linux) 2013-02-12: 23; increased range to 10%
More information about the ghc-commits
mailing list