Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top