Proposal #2560 again: add newtype Down/ReverseOrd to Data.Ord

kahl at cas.mcmaster.ca kahl at cas.mcmaster.ca
Tue Jan 6 10:01:25 EST 2009


Twan van Laarhoven <twanvl at gmail.com> wrote:
 > 
 > About two and a half months ago I proposed that the following newtype (under the 
 > name "Down") be added to Data.Ord:
 > 
 >     newtype ReverseOrd a = ReverseOrd { getReverseOrd :: a }
 > 
 >     instance Ord ReverseOrd where
 >          a <= b = getReverseOrd b <= getReverseOrd a
 >          -- other methods, etc.
 > 
 > [...]
 >
 > I don't really like the name "Reverse",

Me neither...

How about:

-- intended for |qualified| import |as Ord|:
newtype Dual a = Dual { unDual :: a } deriving Eq

instance Ord a => Ord (Dual a) where
  Dual x <=         Dual y  =  y <=         x
  Dual x <          Dual y  =  y <          x
  Dual x >=         Dual y  =  y >=         x
  Dual x >          Dual y  =  y >          x
  Dual x `compare`  Dual y  =  y `compare`  x
  Dual x `min`      Dual y  =  y `max`      x
  Dual x `max`      Dual y  =  y `min`      x


Wolfram


More information about the Libraries mailing list