Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move Down to Data.Ord (#7077)

  • Loading branch information...
commit 3054cf9a85619efb66a4923367532307477db619 1 parent 9aaf76f
@pcapriotti pcapriotti authored
Showing with 12 additions and 11 deletions.
  1. +11 −0 Data/Ord.hs
  2. +1 −11 GHC/Exts.hs
View
11 Data/Ord.hs
@@ -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
View
12 GHC/Exts.hs
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.