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

Stephan Friedrichs deduktionstheorem at web.de
Tue Jan 6 11:34:28 EST 2009


Twan van Laarhoven 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.

IMHO this type is very important! I had to use a hack in my heap package
[1] (see HeapPolicy class and XYPolicy phantom tpyes, they allow
redefining an ordering relation), because there is no such thing in the
base libraries. The aim was to make type safe distinctions between
minimum- and maximum ordered heaps. With a ReverseOrd type, I could just
provide a minimum ordered heap. Then it would be much more obvious, how
to use the package.

I'm not saying that the heap package is the one and only reason for
introducinging something like ReverseOrd, but I am saying that it
addresses a common problem one quickly encounters.

As for the name of the newtype, I'd prefer ReverseOrd, as it best
describes the intended usage: Reversing the ordering relation of a type.

Other possibilities are:
 - FlipOrd (beacuse (flip compare) is the desired effect)
 - Descending[Ord] (opposed to ascending order)
 - Reorder (unfortunately doesn't describe how it's reordered)
just my 2 cents :)

> 
> [...]
> 

Regards,
Stephan

[1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/heap

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr


More information about the Libraries mailing list