Commit 2c3a43db authored by pcapriotti's avatar pcapriotti
Browse files

Move Down to Data.Ord (#7077)

parent 1116d7b2
......@@ -18,6 +18,7 @@
module Data.Ord (
Ord(..),
Ordering(..),
Down(..),
comparing,
) where
......@@ -35,3 +36,13 @@ import GHC.Base
comparing :: (Ord a) => (b -> a) -> b -> b -> Ordering
comparing p x y = compare (p x) (p y)
-- | The 'Down' type allows you to reverse sort order conveniently. A value of type
-- @'Down' a@ contains a value of type @a@ (represented as @'Down' a@).
-- If @a@ has an @'Ord'@ instance associated with it then comparing two
-- values thus wrapped will give you the opposite of their normal sort order.
-- This is particularly useful when sorting in generalised list comprehensions,
-- as in: @then sortWith by 'Down' x@
newtype Down a = Down a deriving (Eq)
instance Ord a => Ord (Down a) where
compare (Down x) (Down y) = y `compare` x
......@@ -72,23 +72,13 @@ import GHC.Stack
import Data.String
import Data.List
import Data.Data
import Data.Ord
import qualified Debug.Trace
-- XXX This should really be in Data.Tuple, where the definitions are
maxTupleSize :: Int
maxTupleSize = 62
-- | The 'Down' type allows you to reverse sort order conveniently. A value of type
-- @'Down' a@ contains a value of type @a@ (represented as @'Down' a@).
-- If @a@ has an @'Ord'@ instance associated with it then comparing two
-- values thus wrapped will give you the opposite of their normal sort order.
-- This is particularly useful when sorting in generalised list comprehensions,
-- as in: @then sortWith by 'Down' x@
newtype Down a = Down a deriving (Eq)
instance Ord a => Ord (Down a) where
compare (Down x) (Down y) = y `compare` x
-- | 'the' ensures that all the elements of the list are identical
-- and then returns that unique element
the :: Eq a => [a] -> a
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment