summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2016-06-04 17:59:47 -0400
committerRyan Scott <ryan.gl.scott@gmail.com>2016-06-04 17:59:48 -0400
commit59651173a52e2400f965e38acd0beb9d0cc14cfe (patch)
treebbcf735fdbf1a7f1975f37b3c5b887a2933016cf /libraries
parentb948a1da7a3929160cb7cb8d6cf2fe79c3081d0a (diff)
downloadhaskell-59651173a52e2400f965e38acd0beb9d0cc14cfe.tar.gz
Replace hand-written Bounded instances with derived ones
Summary: The spiritual successor to D2291, since deriving `Bounded` instances in `GHC.Enum` wasn't possible prior to changes made in that Diff. This Diff finds every manually implemented `Bounded` instance in `base` that is completely equivalent to the derived instances, and replaces it. Reviewers: bgamari, goldfire, austin, hvr Reviewed By: austin, hvr Subscribers: thomie, rwbarton Differential Revision: https://phabricator.haskell.org/D2301
Diffstat (limited to 'libraries')
-rw-r--r--libraries/base/Data/Proxy.hs6
-rw-r--r--libraries/base/Data/Semigroup.hs30
-rw-r--r--libraries/base/Data/Type/Coercion.hs4
-rw-r--r--libraries/base/Data/Type/Equality.hs4
-rw-r--r--libraries/base/GHC/Enum.hs150
5 files changed, 58 insertions, 136 deletions
diff --git a/libraries/base/Data/Proxy.hs b/libraries/base/Data/Proxy.hs
index f0760e855d..a11155844c 100644
--- a/libraries/base/Data/Proxy.hs
+++ b/libraries/base/Data/Proxy.hs
@@ -29,7 +29,7 @@ import GHC.Enum
import GHC.Arr
-- | A concrete, poly-kinded proxy type
-data Proxy t = Proxy
+data Proxy t = Proxy deriving Bounded
-- | A concrete, promotable proxy type, for use at the kind level
-- There are no instances for this because it is intended at the kind level only
@@ -70,10 +70,6 @@ instance Ix (Proxy s) where
unsafeIndex _ _ = 0
unsafeRangeSize _ = 1
-instance Bounded (Proxy s) where
- minBound = Proxy
- maxBound = Proxy
-
instance Monoid (Proxy s) where
mempty = Proxy
mappend _ _ = Proxy
diff --git a/libraries/base/Data/Semigroup.hs b/libraries/base/Data/Semigroup.hs
index 1f4944a411..ff1e4e21bc 100644
--- a/libraries/base/Data/Semigroup.hs
+++ b/libraries/base/Data/Semigroup.hs
@@ -290,11 +290,7 @@ instance Semigroup (NonEmpty a) where
newtype Min a = Min { getMin :: a }
- deriving (Eq, Ord, Show, Read, Data, Generic, Generic1)
-
-instance Bounded a => Bounded (Min a) where
- minBound = Min minBound
- maxBound = Min maxBound
+ deriving (Bounded, Eq, Ord, Show, Read, Data, Generic, Generic1)
instance Enum a => Enum (Min a) where
succ (Min a) = Min (succ a)
@@ -347,11 +343,7 @@ instance Num a => Num (Min a) where
fromInteger = Min . fromInteger
newtype Max a = Max { getMax :: a }
- deriving (Eq, Ord, Show, Read, Data, Generic, Generic1)
-
-instance Bounded a => Bounded (Max a) where
- minBound = Max minBound
- maxBound = Max maxBound
+ deriving (Bounded, Eq, Ord, Show, Read, Data, Generic, Generic1)
instance Enum a => Enum (Max a) where
succ (Max a) = Max (succ a)
@@ -437,11 +429,7 @@ instance Bifunctor Arg where
-- | Use @'Option' ('First' a)@ to get the behavior of
-- 'Data.Monoid.First' from "Data.Monoid".
newtype First a = First { getFirst :: a } deriving
- (Eq, Ord, Show, Read, Data, Generic, Generic1)
-
-instance Bounded a => Bounded (First a) where
- minBound = First minBound
- maxBound = First maxBound
+ (Bounded, Eq, Ord, Show, Read, Data, Generic, Generic1)
instance Enum a => Enum (First a) where
succ (First a) = First (succ a)
@@ -482,11 +470,7 @@ instance MonadFix First where
-- | Use @'Option' ('Last' a)@ to get the behavior of
-- 'Data.Monoid.Last' from "Data.Monoid"
newtype Last a = Last { getLast :: a } deriving
- (Eq, Ord, Show, Read, Data, Generic, Generic1)
-
-instance Bounded a => Bounded (Last a) where
- minBound = Last minBound
- maxBound = Last maxBound
+ (Bounded, Eq, Ord, Show, Read, Data, Generic, Generic1)
instance Enum a => Enum (Last a) where
succ (Last a) = Last (succ a)
@@ -527,7 +511,7 @@ instance MonadFix Last where
-- | Provide a Semigroup for an arbitrary Monoid.
newtype WrappedMonoid m = WrapMonoid { unwrapMonoid :: m }
- deriving (Eq, Ord, Show, Read, Data, Generic, Generic1)
+ deriving (Bounded, Eq, Ord, Show, Read, Data, Generic, Generic1)
instance Monoid m => Semigroup (WrappedMonoid m) where
(<>) = coerce (mappend :: m -> m -> m)
@@ -536,10 +520,6 @@ instance Monoid m => Monoid (WrappedMonoid m) where
mempty = WrapMonoid mempty
mappend = (<>)
-instance Bounded a => Bounded (WrappedMonoid a) where
- minBound = WrapMonoid minBound
- maxBound = WrapMonoid maxBound
-
instance Enum a => Enum (WrappedMonoid a) where
succ (WrapMonoid a) = WrapMonoid (succ a)
pred (WrapMonoid a) = WrapMonoid (pred a)
diff --git a/libraries/base/Data/Type/Coercion.hs b/libraries/base/Data/Type/Coercion.hs
index cc34683f62..00445bc2b9 100644
--- a/libraries/base/Data/Type/Coercion.hs
+++ b/libraries/base/Data/Type/Coercion.hs
@@ -81,9 +81,7 @@ instance Coercible a b => Enum (Coercion a b) where
fromEnum Coercion = 0
-instance Coercible a b => Bounded (Coercion a b) where
- minBound = Coercion
- maxBound = Coercion
+deriving instance Coercible a b => Bounded (Coercion a b)
-- | This class contains types where you can learn the equality of two types
-- from information contained in /terms/. Typically, only singleton types should
diff --git a/libraries/base/Data/Type/Equality.hs b/libraries/base/Data/Type/Equality.hs
index 19c9bcacf2..b22b39d921 100644
--- a/libraries/base/Data/Type/Equality.hs
+++ b/libraries/base/Data/Type/Equality.hs
@@ -131,9 +131,7 @@ instance a ~ b => Enum (a :~: b) where
fromEnum Refl = 0
-instance a ~ b => Bounded (a :~: b) where
- minBound = Refl
- maxBound = Refl
+deriving instance a ~ b => Bounded (a :~: b)
-- | This class contains types where you can learn the equality of two types
-- from information contained in /terms/. Typically, only singleton types should
diff --git a/libraries/base/GHC/Enum.hs b/libraries/base/GHC/Enum.hs
index 729b801dcf..c0e2f5a783 100644
--- a/libraries/base/GHC/Enum.hs
+++ b/libraries/base/GHC/Enum.hs
@@ -1,5 +1,9 @@
+{-# LANGUAGE BangPatterns #-}
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE MagicHash #-}
+{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE Trustworthy #-}
-{-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns, MagicHash #-}
{-# OPTIONS_HADDOCK hide #-}
-----------------------------------------------------------------------------
@@ -150,10 +154,7 @@ predError inst_ty =
-- Tuples
------------------------------------------------------------------------
-instance Bounded () where
- minBound = ()
- maxBound = ()
-
+deriving instance Bounded ()
instance Enum () where
succ _ = errorWithoutStackTrace "Prelude.Enum.().succ: bad argument"
pred _ = errorWithoutStackTrace "Prelude.Enum.().pred: bad argument"
@@ -168,102 +169,54 @@ instance Enum () where
enumFromThenTo () () () = let many = ():many in many
-- Report requires instances up to 15
-instance (Bounded a, Bounded b) => Bounded (a,b) where
- minBound = (minBound, minBound)
- maxBound = (maxBound, maxBound)
-
-instance (Bounded a, Bounded b, Bounded c) => Bounded (a,b,c) where
- minBound = (minBound, minBound, minBound)
- maxBound = (maxBound, maxBound, maxBound)
-
-instance (Bounded a, Bounded b, Bounded c, Bounded d) => Bounded (a,b,c,d) where
- minBound = (minBound, minBound, minBound, minBound)
- maxBound = (maxBound, maxBound, maxBound, maxBound)
-
-instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e) => Bounded (a,b,c,d,e) where
- minBound = (minBound, minBound, minBound, minBound, minBound)
- maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound)
-
-instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f)
- => Bounded (a,b,c,d,e,f) where
- minBound = (minBound, minBound, minBound, minBound, minBound, minBound)
- maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)
-
-instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g)
- => Bounded (a,b,c,d,e,f,g) where
- minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound)
- maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)
-
-instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,
- Bounded h)
- => Bounded (a,b,c,d,e,f,g,h) where
- minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound)
- maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)
-
-instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,
- Bounded h, Bounded i)
- => Bounded (a,b,c,d,e,f,g,h,i) where
- minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,
- minBound)
- maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,
- maxBound)
-
-instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,
- Bounded h, Bounded i, Bounded j)
- => Bounded (a,b,c,d,e,f,g,h,i,j) where
- minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,
- minBound, minBound)
- maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,
- maxBound, maxBound)
-
-instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,
- Bounded h, Bounded i, Bounded j, Bounded k)
- => Bounded (a,b,c,d,e,f,g,h,i,j,k) where
- minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,
- minBound, minBound, minBound)
- maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,
- maxBound, maxBound, maxBound)
-
-instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,
- Bounded h, Bounded i, Bounded j, Bounded k, Bounded l)
- => Bounded (a,b,c,d,e,f,g,h,i,j,k,l) where
- minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,
- minBound, minBound, minBound, minBound)
- maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,
- maxBound, maxBound, maxBound, maxBound)
-
-instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,
- Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m)
- => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m) where
- minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,
- minBound, minBound, minBound, minBound, minBound)
- maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,
- maxBound, maxBound, maxBound, maxBound, maxBound)
-
-instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,
- Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n)
- => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m,n) where
- minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,
- minBound, minBound, minBound, minBound, minBound, minBound)
- maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,
- maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)
-
-instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,
- Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n, Bounded o)
- => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) where
- minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,
- minBound, minBound, minBound, minBound, minBound, minBound, minBound)
- maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,
- maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)
+deriving instance (Bounded a, Bounded b)
+ => Bounded (a,b)
+deriving instance (Bounded a, Bounded b, Bounded c)
+ => Bounded (a,b,c)
+deriving instance (Bounded a, Bounded b, Bounded c, Bounded d)
+ => Bounded (a,b,c,d)
+deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e)
+ => Bounded (a,b,c,d,e)
+deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e,
+ Bounded f)
+ => Bounded (a,b,c,d,e,f)
+deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e,
+ Bounded f, Bounded g)
+ => Bounded (a,b,c,d,e,f,g)
+deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e,
+ Bounded f, Bounded g, Bounded h)
+ => Bounded (a,b,c,d,e,f,g,h)
+deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e,
+ Bounded f, Bounded g, Bounded h, Bounded i)
+ => Bounded (a,b,c,d,e,f,g,h,i)
+deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e,
+ Bounded f, Bounded g, Bounded h, Bounded i, Bounded j)
+ => Bounded (a,b,c,d,e,f,g,h,i,j)
+deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e,
+ Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k)
+ => Bounded (a,b,c,d,e,f,g,h,i,j,k)
+deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e,
+ Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k,
+ Bounded l)
+ => Bounded (a,b,c,d,e,f,g,h,i,j,k,l)
+deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e,
+ Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k,
+ Bounded l, Bounded m)
+ => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m)
+deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e,
+ Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k,
+ Bounded l, Bounded m, Bounded n)
+ => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m,n)
+deriving instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e,
+ Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k,
+ Bounded l, Bounded m, Bounded n, Bounded o)
+ => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)
------------------------------------------------------------------------
-- Bool
------------------------------------------------------------------------
-instance Bounded Bool where
- minBound = False
- maxBound = True
-
+deriving instance Bounded Bool
instance Enum Bool where
succ False = True
succ True = errorWithoutStackTrace "Prelude.Enum.Bool.succ: bad argument"
@@ -286,10 +239,7 @@ instance Enum Bool where
-- Ordering
------------------------------------------------------------------------
-instance Bounded Ordering where
- minBound = LT
- maxBound = GT
-
+deriving instance Bounded Ordering
instance Enum Ordering where
succ LT = EQ
succ EQ = GT