Teo Camarasu pushed to branch wip/T26834 at Glasgow Haskell Compiler / GHC
Commits:
-
2af36711
by Teo Camarasu at 2026-01-29T13:06:59+00:00
13 changed files:
- libraries/base/src/Data/Foldable1.hs
- libraries/base/src/Data/Functor/Classes.hs
- libraries/base/src/Data/Ord.hs
- libraries/ghc-internal/ghc-internal.cabal.in
- libraries/ghc-internal/src/GHC/Internal/Control/Monad/Fix.hs
- libraries/ghc-internal/src/GHC/Internal/Control/Monad/Zip.hs
- libraries/ghc-internal/src/GHC/Internal/Data/Data.hs
- libraries/ghc-internal/src/GHC/Internal/Data/Foldable.hs
- libraries/ghc-internal/src/GHC/Internal/Data/Ord.hs
- + libraries/ghc-internal/src/GHC/Internal/Data/Ord/Down.hs
- libraries/ghc-internal/src/GHC/Internal/Data/Traversable.hs
- libraries/ghc-internal/src/GHC/Internal/Exts.hs
- libraries/ghc-internal/src/GHC/Internal/Generics.hs
Changes:
| ... | ... | @@ -45,7 +45,7 @@ import Data.Complex (Complex (..)) |
| 45 | 45 | import GHC.Generics
|
| 46 | 46 | (M1 (..), Par1 (..), Rec1 (..), V1, (:*:) (..), (:+:) (..), (:.:) (..))
|
| 47 | 47 | |
| 48 | -import GHC.Internal.Data.Ord (Down (..))
|
|
| 48 | +import GHC.Internal.Data.Ord.Down (Down (..))
|
|
| 49 | 49 | |
| 50 | 50 | import qualified GHC.Internal.Data.Monoid as Mon
|
| 51 | 51 |
| ... | ... | @@ -76,7 +76,7 @@ import Control.Applicative (Alternative((<|>)), Const(Const)) |
| 76 | 76 | import GHC.Internal.Data.Functor.Identity (Identity(Identity))
|
| 77 | 77 | import GHC.Internal.Data.Proxy (Proxy(Proxy))
|
| 78 | 78 | import Data.List.NonEmpty (NonEmpty(..))
|
| 79 | -import GHC.Internal.Data.Ord (Down(Down))
|
|
| 79 | +import GHC.Internal.Data.Ord.Down (Down(Down))
|
|
| 80 | 80 | import Data.Complex (Complex((:+)))
|
| 81 | 81 | |
| 82 | 82 | import GHC.Generics (Generic1(..), Generically1(..), V1, U1(..), Par1(..), Rec1(..), K1(..), M1(..) , (:+:)(..), (:*:)(..), (:.:)(..), URec(..), UAddr, UChar, UDouble, UFloat, UInt, UWord)
|
| ... | ... | @@ -21,4 +21,5 @@ module Data.Ord |
| 21 | 21 | clamp
|
| 22 | 22 | ) where
|
| 23 | 23 | |
| 24 | -import GHC.Internal.Data.Ord |
|
| \ No newline at end of file | ||
| 24 | +import GHC.Internal.Data.Ord
|
|
| 25 | +import GHC.Internal.Data.Ord.Down |
| ... | ... | @@ -160,6 +160,7 @@ Library |
| 160 | 160 | GHC.Internal.Data.NonEmpty
|
| 161 | 161 | GHC.Internal.Data.OldList
|
| 162 | 162 | GHC.Internal.Data.Ord
|
| 163 | + GHC.Internal.Data.Ord.Down
|
|
| 163 | 164 | GHC.Internal.Data.Proxy
|
| 164 | 165 | GHC.Internal.Data.Semigroup.Internal
|
| 165 | 166 | GHC.Internal.Data.STRef
|
| ... | ... | @@ -576,4 +577,4 @@ Library |
| 576 | 577 | ghc-options: -this-unit-id ghc-internal
|
| 577 | 578 | |
| 578 | 579 | -- Make sure we don't accidentally regress into anti-patterns
|
| 579 | - ghc-options: -Wcompat -Wnoncanonical-monad-instances |
|
| 580 | + ghc-options: -Wcompat -Wnoncanonical-monad-instances -Werror=unused-imports |
| ... | ... | @@ -33,7 +33,6 @@ import GHC.Internal.Data.Maybe |
| 33 | 33 | import GHC.Internal.Data.Monoid ( Monoid, Dual(..), Sum(..), Product(..)
|
| 34 | 34 | , First(..), Last(..), Alt(..), Ap(..) )
|
| 35 | 35 | import GHC.Internal.Data.NonEmpty ( NonEmpty(..) )
|
| 36 | -import GHC.Internal.Data.Ord ( Down(..) )
|
|
| 37 | 36 | import GHC.Internal.Data.Tuple ( Solo(..), snd )
|
| 38 | 37 | import GHC.Internal.Base ( Monad, errorWithoutStackTrace, (.) )
|
| 39 | 38 | import GHC.Internal.Generics
|
| ... | ... | @@ -167,13 +166,6 @@ instance (MonadFix f, MonadFix g) => MonadFix (f :*: g) where |
| 167 | 166 | fstP (a :*: _) = a
|
| 168 | 167 | sndP (_ :*: b) = b
|
| 169 | 168 | |
| 170 | --- Instances for Data.Ord
|
|
| 171 | - |
|
| 172 | --- | @since base-4.12.0.0
|
|
| 173 | -instance MonadFix Down where
|
|
| 174 | - mfix f = Down (fix (getDown . f))
|
|
| 175 | - |
|
| 176 | - |
|
| 177 | 169 | -- | @since base-4.8.0.0
|
| 178 | 170 | instance MonadFix Identity where
|
| 179 | 171 | mfix f = Identity (fix (runIdentity . f)) |
| ... | ... | @@ -23,7 +23,6 @@ import GHC.Internal.Data.Functor.Identity |
| 23 | 23 | import qualified GHC.Internal.Data.Functor
|
| 24 | 24 | import GHC.Internal.Data.Monoid
|
| 25 | 25 | import GHC.Internal.Data.NonEmpty ( NonEmpty(..) )
|
| 26 | -import GHC.Internal.Data.Ord ( Down(..) )
|
|
| 27 | 26 | import GHC.Internal.Data.Proxy
|
| 28 | 27 | --import qualified Data.List.NonEmpty as NE
|
| 29 | 28 | import GHC.Internal.Generics
|
| ... | ... | @@ -136,9 +135,3 @@ instance MonadZip f => MonadZip (M1 i c f) where |
| 136 | 135 | -- | @since 4.9.0.0
|
| 137 | 136 | instance (MonadZip f, MonadZip g) => MonadZip (f :*: g) where
|
| 138 | 137 | mzipWith f (x1 :*: y1) (x2 :*: y2) = mzipWith f x1 x2 :*: mzipWith f y1 y2 |
| 139 | - |
|
| 140 | --- instances for GHC.Internal.Data.Ord
|
|
| 141 | - |
|
| 142 | --- | @since 4.12.0.0
|
|
| 143 | -instance MonadZip Down where
|
|
| 144 | - mzipWith = liftM2 |
| ... | ... | @@ -116,7 +116,7 @@ import GHC.Internal.Data.Eq |
| 116 | 116 | import GHC.Internal.Data.Maybe
|
| 117 | 117 | import GHC.Internal.Data.Monoid
|
| 118 | 118 | import GHC.Internal.Data.NonEmpty ( NonEmpty(..) )
|
| 119 | -import GHC.Internal.Data.Ord
|
|
| 119 | +import GHC.Internal.Data.Ord.Down
|
|
| 120 | 120 | import GHC.Internal.Data.OldList (findIndex)
|
| 121 | 121 | import GHC.Internal.Data.Typeable
|
| 122 | 122 | import GHC.Internal.Data.Version( Version(..) )
|
| ... | ... | @@ -921,9 +921,6 @@ deriving instance Foldable UInt |
| 921 | 921 | -- | @since base-4.9.0.0
|
| 922 | 922 | deriving instance Foldable UWord
|
| 923 | 923 | |
| 924 | --- Instances for Data.Ord
|
|
| 925 | --- | @since base-4.12.0.0
|
|
| 926 | -deriving instance Foldable Down
|
|
| 927 | 924 | |
| 928 | 925 | -- | Right-to-left monadic fold over the elements of a structure.
|
| 929 | 926 | --
|
| ... | ... | @@ -19,21 +19,11 @@ |
| 19 | 19 | module GHC.Internal.Data.Ord (
|
| 20 | 20 | Ord(..),
|
| 21 | 21 | Ordering(..),
|
| 22 | - Down(..),
|
|
| 23 | 22 | comparing,
|
| 24 | 23 | clamp,
|
| 25 | 24 | ) where
|
| 26 | 25 | |
| 27 | -import GHC.Internal.Data.Bits (Bits, FiniteBits, complement)
|
|
| 28 | -import GHC.Internal.Foreign.Storable (Storable)
|
|
| 29 | -import GHC.Internal.Ix (Ix)
|
|
| 30 | 26 | import GHC.Internal.Base
|
| 31 | -import GHC.Internal.Enum (Bounded(..), Enum(..))
|
|
| 32 | -import GHC.Internal.Float (Floating, RealFloat)
|
|
| 33 | -import GHC.Internal.Num
|
|
| 34 | -import GHC.Internal.Read
|
|
| 35 | -import GHC.Internal.Real (Fractional, Real, RealFrac)
|
|
| 36 | -import GHC.Internal.Show
|
|
| 37 | 27 | |
| 38 | 28 | -- $setup
|
| 39 | 29 | -- >>> import Prelude
|
| ... | ... | @@ -68,115 +58,3 @@ comparing p x y = compare (p x) (p y) |
| 68 | 58 | -- @since base-4.16.0.0
|
| 69 | 59 | clamp :: (Ord a) => (a, a) -> a -> a
|
| 70 | 60 | clamp (low, high) a = min high (max a low) |
| 71 | - |
|
| 72 | --- | The 'Down' type allows you to reverse sort order conveniently. A value of type
|
|
| 73 | --- @'Down' a@ contains a value of type @a@ (represented as @'Down' a@).
|
|
| 74 | ---
|
|
| 75 | --- If @a@ has an @'Ord'@ instance associated with it then comparing two
|
|
| 76 | --- values thus wrapped will give you the opposite of their normal sort order.
|
|
| 77 | --- This is particularly useful when sorting in generalised list comprehensions,
|
|
| 78 | --- as in: @then sortWith by 'Down' x@.
|
|
| 79 | ---
|
|
| 80 | --- >>> compare True False
|
|
| 81 | --- GT
|
|
| 82 | ---
|
|
| 83 | --- >>> compare (Down True) (Down False)
|
|
| 84 | --- LT
|
|
| 85 | ---
|
|
| 86 | --- If @a@ has a @'Bounded'@ instance then the wrapped instance also respects
|
|
| 87 | --- the reversed ordering by exchanging the values of @'minBound'@ and
|
|
| 88 | --- @'maxBound'@.
|
|
| 89 | ---
|
|
| 90 | --- >>> minBound :: Int
|
|
| 91 | --- -9223372036854775808
|
|
| 92 | ---
|
|
| 93 | --- >>> minBound :: Down Int
|
|
| 94 | --- Down 9223372036854775807
|
|
| 95 | ---
|
|
| 96 | --- All other instances of @'Down' a@ behave as they do for @a@.
|
|
| 97 | ---
|
|
| 98 | --- @since base-4.6.0.0
|
|
| 99 | -newtype Down a = Down
|
|
| 100 | - { getDown :: a -- ^ @since base-4.14.0.0
|
|
| 101 | - }
|
|
| 102 | - deriving
|
|
| 103 | - ( Eq -- ^ @since base-4.6.0.0
|
|
| 104 | - , Num -- ^ @since base-4.11.0.0
|
|
| 105 | - , Semigroup -- ^ @since base-4.11.0.0
|
|
| 106 | - , Monoid -- ^ @since base-4.11.0.0
|
|
| 107 | - , Bits -- ^ @since base-4.14.0.0
|
|
| 108 | - , FiniteBits -- ^ @since base-4.14.0.0
|
|
| 109 | - , Floating -- ^ @since base-4.14.0.0
|
|
| 110 | - , Fractional -- ^ @since base-4.14.0.0
|
|
| 111 | - , Ix -- ^ @since base-4.14.0.0
|
|
| 112 | - , Real -- ^ @since base-4.14.0.0
|
|
| 113 | - , RealFrac -- ^ @since base-4.14.0.0
|
|
| 114 | - , RealFloat -- ^ @since base-4.14.0.0
|
|
| 115 | - , Storable -- ^ @since base-4.14.0.0
|
|
| 116 | - )
|
|
| 117 | - |
|
| 118 | --- | This instance would be equivalent to the derived instances of the
|
|
| 119 | --- 'Down' newtype if the 'getDown' field were removed
|
|
| 120 | ---
|
|
| 121 | --- @since base-4.7.0.0
|
|
| 122 | -instance (Read a) => Read (Down a) where
|
|
| 123 | - readsPrec d = readParen (d > 10) $ \ r ->
|
|
| 124 | - [(Down x,t) | ("Down",s) <- lex r, (x,t) <- readsPrec 11 s]
|
|
| 125 | - |
|
| 126 | --- | This instance would be equivalent to the derived instances of the
|
|
| 127 | --- 'Down' newtype if the 'getDown' field were removed
|
|
| 128 | ---
|
|
| 129 | --- @since base-4.7.0.0
|
|
| 130 | -instance (Show a) => Show (Down a) where
|
|
| 131 | - showsPrec d (Down x) = showParen (d > 10) $
|
|
| 132 | - showString "Down " . showsPrec 11 x
|
|
| 133 | - |
|
| 134 | --- | @since base-4.6.0.0
|
|
| 135 | -instance Ord a => Ord (Down a) where
|
|
| 136 | - compare (Down x) (Down y) = y `compare` x
|
|
| 137 | - Down x < Down y = y < x
|
|
| 138 | - Down x > Down y = y > x
|
|
| 139 | - Down x <= Down y = y <= x
|
|
| 140 | - Down x >= Down y = y >= x
|
|
| 141 | - min (Down x) (Down y) = Down (max y x)
|
|
| 142 | - max (Down x) (Down y) = Down (min y x)
|
|
| 143 | - |
|
| 144 | --- | Swaps @'minBound'@ and @'maxBound'@ of the underlying type.
|
|
| 145 | ---
|
|
| 146 | --- @since base-4.14.0.0
|
|
| 147 | -instance Bounded a => Bounded (Down a) where
|
|
| 148 | - minBound = Down maxBound
|
|
| 149 | - maxBound = Down minBound
|
|
| 150 | - |
|
| 151 | --- | Swaps @'succ'@ and @'pred'@ of the underlying type.
|
|
| 152 | ---
|
|
| 153 | --- @since base-4.18.0.0
|
|
| 154 | -instance (Enum a, Bounded a, Eq a) => Enum (Down a) where
|
|
| 155 | - succ = fmap pred
|
|
| 156 | - pred = fmap succ
|
|
| 157 | - |
|
| 158 | - -- Here we use the fact that 'comparing (complement @Int)' behaves
|
|
| 159 | - -- as an order-swapping `compare @Int`.
|
|
| 160 | - fromEnum = complement . fromEnum . getDown
|
|
| 161 | - toEnum = Down . toEnum . complement
|
|
| 162 | - |
|
| 163 | - enumFrom (Down x)
|
|
| 164 | - | x == minBound
|
|
| 165 | - = [Down x] -- We can't rely on 'enumFromThen _ (pred @a minBound)` behaving nicely,
|
|
| 166 | - -- since 'enumFromThen _' might be strict and 'pred minBound' might throw
|
|
| 167 | - | otherwise
|
|
| 168 | - = coerce $ enumFromThen x (pred x)
|
|
| 169 | - enumFromThen (Down x) (Down y) = coerce $ enumFromThen x y
|
|
| 170 | - |
|
| 171 | --- | @since base-4.11.0.0
|
|
| 172 | -instance Functor Down where
|
|
| 173 | - fmap = coerce
|
|
| 174 | - |
|
| 175 | --- | @since base-4.11.0.0
|
|
| 176 | -instance Applicative Down where
|
|
| 177 | - pure = Down
|
|
| 178 | - (<*>) = coerce
|
|
| 179 | - |
|
| 180 | --- | @since base-4.11.0.0
|
|
| 181 | -instance Monad Down where
|
|
| 182 | - Down a >>= k = k a |
| 1 | +{-# LANGUAGE Trustworthy #-}
|
|
| 2 | +{-# LANGUAGE NoImplicitPrelude #-}
|
|
| 3 | +{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
|
| 4 | +{-# LANGUAGE DeriveGeneric #-}
|
|
| 5 | +{-# LANGUAGE DeriveFoldable #-}
|
|
| 6 | +{-# LANGUAGE DeriveTraversable #-}
|
|
| 7 | +{-# LANGUAGE StandaloneDeriving #-}
|
|
| 8 | + |
|
| 9 | +-----------------------------------------------------------------------------
|
|
| 10 | +-- |
|
|
| 11 | +-- Module : GHC.Internal.Data.Ord.Down
|
|
| 12 | +-- Copyright : (c) The University of Glasgow 2005
|
|
| 13 | +-- License : BSD-style (see the file libraries/base/LICENSE)
|
|
| 14 | +--
|
|
| 15 | +-- Maintainer : libraries@haskell.org
|
|
| 16 | +-- Stability : stable
|
|
| 17 | +-- Portability : portable
|
|
| 18 | +--
|
|
| 19 | +-- Orderings
|
|
| 20 | +--
|
|
| 21 | +-----------------------------------------------------------------------------
|
|
| 22 | + |
|
| 23 | +module GHC.Internal.Data.Ord.Down (
|
|
| 24 | + Down(..),
|
|
| 25 | + ) where
|
|
| 26 | + |
|
| 27 | +import GHC.Internal.Data.Bits (Bits, FiniteBits, complement)
|
|
| 28 | +import GHC.Internal.Ix (Ix)
|
|
| 29 | +import GHC.Internal.Foreign.Storable (Storable)
|
|
| 30 | +import GHC.Internal.Base
|
|
| 31 | +import GHC.Internal.Enum (Bounded(..), Enum(..))
|
|
| 32 | +import GHC.Internal.Float (Floating, RealFloat)
|
|
| 33 | +import GHC.Internal.Num
|
|
| 34 | +import GHC.Internal.Read
|
|
| 35 | +import GHC.Internal.Real (Fractional, Real, RealFrac)
|
|
| 36 | +import GHC.Internal.Show
|
|
| 37 | +import GHC.Internal.Generics
|
|
| 38 | +import GHC.Internal.Data.Foldable
|
|
| 39 | +import GHC.Internal.Data.Traversable
|
|
| 40 | +import GHC.Internal.Control.Monad.Zip
|
|
| 41 | + |
|
| 42 | +-- $setup
|
|
| 43 | +-- >>> import Prelude
|
|
| 44 | + |
|
| 45 | +-- | The 'Down' type allows you to reverse sort order conveniently. A value of type
|
|
| 46 | +-- @'Down' a@ contains a value of type @a@ (represented as @'Down' a@).
|
|
| 47 | +--
|
|
| 48 | +-- If @a@ has an @'Ord'@ instance associated with it then comparing two
|
|
| 49 | +-- values thus wrapped will give you the opposite of their normal sort order.
|
|
| 50 | +-- This is particularly useful when sorting in generalised list comprehensions,
|
|
| 51 | +-- as in: @then sortWith by 'Down' x@.
|
|
| 52 | +--
|
|
| 53 | +-- >>> compare True False
|
|
| 54 | +-- GT
|
|
| 55 | +--
|
|
| 56 | +-- >>> compare (Down True) (Down False)
|
|
| 57 | +-- LT
|
|
| 58 | +--
|
|
| 59 | +-- If @a@ has a @'Bounded'@ instance then the wrapped instance also respects
|
|
| 60 | +-- the reversed ordering by exchanging the values of @'minBound'@ and
|
|
| 61 | +-- @'maxBound'@.
|
|
| 62 | +--
|
|
| 63 | +-- >>> minBound :: Int
|
|
| 64 | +-- -9223372036854775808
|
|
| 65 | +--
|
|
| 66 | +-- >>> minBound :: Down Int
|
|
| 67 | +-- Down 9223372036854775807
|
|
| 68 | +--
|
|
| 69 | +-- All other instances of @'Down' a@ behave as they do for @a@.
|
|
| 70 | +--
|
|
| 71 | +-- @since base-4.6.0.0
|
|
| 72 | +newtype Down a = Down
|
|
| 73 | + { getDown :: a -- ^ @since base-4.14.0.0
|
|
| 74 | + }
|
|
| 75 | + deriving
|
|
| 76 | + ( Eq -- ^ @since base-4.6.0.0
|
|
| 77 | + , Num -- ^ @since base-4.11.0.0
|
|
| 78 | + , Semigroup -- ^ @since base-4.11.0.0
|
|
| 79 | + , Monoid -- ^ @since base-4.11.0.0
|
|
| 80 | + , Bits -- ^ @since base-4.14.0.0
|
|
| 81 | + , FiniteBits -- ^ @since base-4.14.0.0
|
|
| 82 | + , Floating -- ^ @since base-4.14.0.0
|
|
| 83 | + , Fractional -- ^ @since base-4.14.0.0
|
|
| 84 | + , Ix -- ^ @since base-4.14.0.0
|
|
| 85 | + , Real -- ^ @since base-4.14.0.0
|
|
| 86 | + , RealFrac -- ^ @since base-4.14.0.0
|
|
| 87 | + , RealFloat -- ^ @since base-4.14.0.0
|
|
| 88 | + , Storable -- ^ @since base-4.14.0.0
|
|
| 89 | + , Generic -- ^ @since base-4.12.0.0
|
|
| 90 | + )
|
|
| 91 | + |
|
| 92 | +-- | @since base-4.12.0.0
|
|
| 93 | +deriving instance Generic1 Down
|
|
| 94 | + |
|
| 95 | +-- | @since base-4.12.0.0
|
|
| 96 | +deriving instance Foldable Down
|
|
| 97 | + |
|
| 98 | +-- | @since base-4.12.0.0
|
|
| 99 | +deriving instance Traversable Down
|
|
| 100 | + |
|
| 101 | +-- | @since 4.12.0.0
|
|
| 102 | +instance MonadZip Down where
|
|
| 103 | + mzipWith = liftM2
|
|
| 104 | + |
|
| 105 | +-- | This instance would be equivalent to the derived instances of the
|
|
| 106 | +-- 'Down' newtype if the 'getDown' field were removed
|
|
| 107 | +--
|
|
| 108 | +-- @since base-4.7.0.0
|
|
| 109 | +instance (Read a) => Read (Down a) where
|
|
| 110 | + readsPrec d = readParen (d > 10) $ \ r ->
|
|
| 111 | + [(Down x,t) | ("Down",s) <- lex r, (x,t) <- readsPrec 11 s]
|
|
| 112 | + |
|
| 113 | +-- | This instance would be equivalent to the derived instances of the
|
|
| 114 | +-- 'Down' newtype if the 'getDown' field were removed
|
|
| 115 | +--
|
|
| 116 | +-- @since base-4.7.0.0
|
|
| 117 | +instance (Show a) => Show (Down a) where
|
|
| 118 | + showsPrec d (Down x) = showParen (d > 10) $
|
|
| 119 | + showString "Down " . showsPrec 11 x
|
|
| 120 | + |
|
| 121 | +-- | @since base-4.6.0.0
|
|
| 122 | +instance Ord a => Ord (Down a) where
|
|
| 123 | + compare (Down x) (Down y) = y `compare` x
|
|
| 124 | + Down x < Down y = y < x
|
|
| 125 | + Down x > Down y = y > x
|
|
| 126 | + Down x <= Down y = y <= x
|
|
| 127 | + Down x >= Down y = y >= x
|
|
| 128 | + min (Down x) (Down y) = Down (max y x)
|
|
| 129 | + max (Down x) (Down y) = Down (min y x)
|
|
| 130 | + |
|
| 131 | +-- | Swaps @'minBound'@ and @'maxBound'@ of the underlying type.
|
|
| 132 | +--
|
|
| 133 | +-- @since base-4.14.0.0
|
|
| 134 | +instance Bounded a => Bounded (Down a) where
|
|
| 135 | + minBound = Down maxBound
|
|
| 136 | + maxBound = Down minBound
|
|
| 137 | + |
|
| 138 | +-- | Swaps @'succ'@ and @'pred'@ of the underlying type.
|
|
| 139 | +--
|
|
| 140 | +-- @since base-4.18.0.0
|
|
| 141 | +instance (Enum a, Bounded a, Eq a) => Enum (Down a) where
|
|
| 142 | + succ = fmap pred
|
|
| 143 | + pred = fmap succ
|
|
| 144 | + |
|
| 145 | + -- Here we use the fact that 'comparing (complement @Int)' behaves
|
|
| 146 | + -- as an order-swapping `compare @Int`.
|
|
| 147 | + fromEnum = complement . fromEnum . getDown
|
|
| 148 | + toEnum = Down . toEnum . complement
|
|
| 149 | + |
|
| 150 | + enumFrom (Down x)
|
|
| 151 | + | x == minBound
|
|
| 152 | + = [Down x] -- We can't rely on 'enumFromThen _ (pred @a minBound)` behaving nicely,
|
|
| 153 | + -- since 'enumFromThen _' might be strict and 'pred minBound' might throw
|
|
| 154 | + | otherwise
|
|
| 155 | + = coerce $ enumFromThen x (pred x)
|
|
| 156 | + enumFromThen (Down x) (Down y) = coerce $ enumFromThen x y
|
|
| 157 | + |
|
| 158 | +-- | @since base-4.11.0.0
|
|
| 159 | +instance Functor Down where
|
|
| 160 | + fmap = coerce
|
|
| 161 | + |
|
| 162 | +-- | @since base-4.11.0.0
|
|
| 163 | +instance Applicative Down where
|
|
| 164 | + pure = Down
|
|
| 165 | + (<*>) = coerce
|
|
| 166 | + |
|
| 167 | +-- | @since base-4.11.0.0
|
|
| 168 | +instance Monad Down where
|
|
| 169 | + Down a >>= k = k a |
| ... | ... | @@ -46,7 +46,6 @@ import GHC.Internal.Data.Functor.Identity ( Identity(..) ) |
| 46 | 46 | import GHC.Internal.Data.Functor.Utils ( StateL(..), StateR(..), StateT(..), (#.) )
|
| 47 | 47 | import GHC.Internal.Data.Monoid ( Dual(..), Sum(..), Product(..),
|
| 48 | 48 | First(..), Last(..), Alt(..), Ap(..) )
|
| 49 | -import GHC.Internal.Data.Ord ( Down(..) )
|
|
| 50 | 49 | import GHC.Internal.Data.Proxy ( Proxy(..) )
|
| 51 | 50 | |
| 52 | 51 | import GHC.Internal.Arr
|
| ... | ... | @@ -364,10 +363,6 @@ deriving instance Traversable UInt |
| 364 | 363 | -- | @since base-4.9.0.0
|
| 365 | 364 | deriving instance Traversable UWord
|
| 366 | 365 | |
| 367 | --- Instance for Data.Ord
|
|
| 368 | --- | @since base-4.12.0.0
|
|
| 369 | -deriving instance Traversable Down
|
|
| 370 | - |
|
| 371 | 366 | -- general functions
|
| 372 | 367 | |
| 373 | 368 | -- | 'for' is 'traverse' with its arguments flipped. For a version
|
| ... | ... | @@ -318,7 +318,7 @@ import qualified GHC.Internal.Data.Coerce |
| 318 | 318 | import GHC.Internal.Data.String
|
| 319 | 319 | import GHC.Internal.Data.OldList
|
| 320 | 320 | import GHC.Internal.Data.Data
|
| 321 | -import GHC.Internal.Data.Ord
|
|
| 321 | +import GHC.Internal.Data.Ord.Down
|
|
| 322 | 322 | import qualified GHC.Internal.Debug.Trace
|
| 323 | 323 | import GHC.Internal.Unsafe.Coerce ( unsafeCoerce# ) -- just for re-export
|
| 324 | 324 |
| ... | ... | @@ -732,7 +732,6 @@ module GHC.Internal.Generics ( |
| 732 | 732 | -- We use some base types
|
| 733 | 733 | import GHC.Internal.Data.Either ( Either (..) )
|
| 734 | 734 | import GHC.Internal.Data.Maybe ( Maybe(..), fromMaybe )
|
| 735 | -import GHC.Internal.Data.Ord ( Down(..) )
|
|
| 736 | 735 | import GHC.Internal.Bignum.Integer ( Integer, integerToInt )
|
| 737 | 736 | import GHC.Internal.Prim ( Addr#, Char#, Double#, Float#, Int#, Word# )
|
| 738 | 737 | import GHC.Internal.Ptr ( Ptr(..) )
|
| ... | ... | @@ -1629,9 +1628,6 @@ deriving instance Generic ((,,,,,,,,,,,,,) a b c d e f g h i j k l m n) |
| 1629 | 1628 | -- | @since base-4.16.0.0
|
| 1630 | 1629 | deriving instance Generic ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o)
|
| 1631 | 1630 | |
| 1632 | --- | @since base-4.12.0.0
|
|
| 1633 | -deriving instance Generic (Down a)
|
|
| 1634 | - |
|
| 1635 | 1631 | -- | @since base-4.15.0.0
|
| 1636 | 1632 | deriving instance Generic SrcLoc
|
| 1637 | 1633 | |
| ... | ... | @@ -1701,9 +1697,6 @@ deriving instance Generic1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m) |
| 1701 | 1697 | -- | @since base-4.16.0.0
|
| 1702 | 1698 | deriving instance Generic1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n)
|
| 1703 | 1699 | |
| 1704 | --- | @since base-4.12.0.0
|
|
| 1705 | -deriving instance Generic1 Down
|
|
| 1706 | - |
|
| 1707 | 1700 | --------------------------------------------------------------------------------
|
| 1708 | 1701 | -- Copied from the singletons package
|
| 1709 | 1702 | --------------------------------------------------------------------------------
|