Proposal: add an order-reversing newtype to Data.Ord

ARJANEN Loïc Jean David arjanen.loic at gmail.com
Thu Jun 28 12:01:06 CEST 2012


Hello all,

I recently noticed that despite conversations about that in this
mailing-list, there isn't an order-reversing newtype in Data.Ord.
That newtype would be quite useful, e.g. for reverse-sorting a list or
a set, so I propose we add a newtype defined thusly:

   newtype Reverse a = Reverse { fromReverse :: a } deriving (Eq)

   instance Ord a => Ord (Reverse a) where
      compare (Reverse x) (Reverse y) = compare y x

I took the implementation from the Down newtype in GHC.Exts, so we
could perhaps just re-export it.
This will cause breakage to code already defining a type named
Reverse, so I don't know if the damage will be important. Of course,
the name and definition are open to discussion.

Deadline: 12 July 2012.

P.S. : A conversation about that took place here:
http://haskell.1045720.n5.nabble.com/A-Down-newtype-in-Data-Ord-td5005373.html

-- 
ARJANEN Loïc Jean David
http://blog.luigiscorner.com
---
"Computer science is no more about computers than astronomy is about
telescopes, biology is about microscopes, or chemistry is about
beakers and test tubes. Science is not about tools. It is about how we
use them, and what we find out when we do."
Michael R. Fellows and Ian Parberry



More information about the Libraries mailing list