summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFumiaki Kinoshita <fumiexcel@gmail.com>2019-05-05 13:25:15 +0900
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-06-18 16:00:20 -0400
commit62f0213d4db6020a0d1feb8512432dcad36f08de (patch)
treea8a0179571cfc23a251d817adcec42a9e85d618e
parent24afbfe9aacbb3f6a5cec8875ab100f0dfbe1bf8 (diff)
downloadhaskell-62f0213d4db6020a0d1feb8512432dcad36f08de.tar.gz
Data.Ord: give a field name getDown to Down
-rw-r--r--libraries/base/Control/Monad/Fix.hs1
-rw-r--r--libraries/base/Data/Ord.hs22
-rw-r--r--libraries/base/changelog.md2
3 files changed, 21 insertions, 4 deletions
diff --git a/libraries/base/Control/Monad/Fix.hs b/libraries/base/Control/Monad/Fix.hs
index d9a58485f2..96133777be 100644
--- a/libraries/base/Control/Monad/Fix.hs
+++ b/libraries/base/Control/Monad/Fix.hs
@@ -156,4 +156,3 @@ instance (MonadFix f, MonadFix g) => MonadFix (f :*: g) where
-- | @since 4.12.0.0
instance MonadFix Down where
mfix f = Down (fix (getDown . f))
- where getDown (Down x) = x
diff --git a/libraries/base/Data/Ord.hs b/libraries/base/Data/Ord.hs
index c6b7e59543..29f4fb3582 100644
--- a/libraries/base/Data/Ord.hs
+++ b/libraries/base/Data/Ord.hs
@@ -46,16 +46,32 @@ comparing p x y = compare (p x) (p y)
-- as in: @then sortWith by 'Down' x@
--
-- @since 4.6.0.0
-newtype Down a = Down a
+newtype Down a = Down
+ { getDown :: a -- ^ @since 4.14.0.0
+ }
deriving
( Eq -- ^ @since 4.6.0.0
- , Show -- ^ @since 4.7.0.0
- , Read -- ^ @since 4.7.0.0
, Num -- ^ @since 4.11.0.0
, Semigroup -- ^ @since 4.11.0.0
, Monoid -- ^ @since 4.11.0.0
)
+-- | This instance would be equivalent to the derived instances of the
+-- 'Down' newtype if the 'getDown' field were removed
+--
+-- @since 4.7.0.0
+instance (Read a) => Read (Down a) where
+ readsPrec d = readParen (d > 10) $ \ r ->
+ [(Down x,t) | ("Down",s) <- lex r, (x,t) <- readsPrec 11 s]
+
+-- | This instance would be equivalent to the derived instances of the
+-- 'Down' newtype if the 'getDown' field were removed
+--
+-- @since 4.7.0.0
+instance (Show a) => Show (Down a) where
+ showsPrec d (Down x) = showParen (d > 10) $
+ showString "Down " . showsPrec 11 x
+
-- | @since 4.6.0.0
instance Ord a => Ord (Down a) where
compare (Down x) (Down y) = y `compare` x
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 3c12e7c511..5b874b4c7e 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -5,6 +5,8 @@
* Add a `TestEquality` instance for the `Compose` newtype.
+ * `Data.Ord.Down` now has a field name, `getDown`
+
* Fix the `integer-gmp` variant of `isValidNatural`: Previously it would fail
to detect values `<= maxBound::Word` that were incorrectly encoded using
the `NatJ#` constructor.