Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell newtype that reverses or flips order

There's probably already a newtype that flips the sense of Ord, Bounded, etc. Something along the lines of

newtype FlipOrd a = FlipOrd {unFlip :: a} deriving (Eq)

instance (Ord a) => Ord (FlipOrd a) where
    compare = flip compare

instance (Bounded a) => Bounded (FlipOrd a) where
    minBound = FlipOrd maxBound
    maxBound = FlipOrd minBound

Where does this live in the existing Haskell packages?

Note: There's an existing Reverse Functor, which does something very different, and fortunately has a completely incompatible kind.

like image 718
Cirdec Avatar asked Nov 18 '13 21:11

Cirdec


1 Answers

It's simply in Data.Ord: Down. (This doesn't have a Bounded instance, though.)

like image 176
leftaroundabout Avatar answered Sep 24 '22 10:09

leftaroundabout