[extra classes for data.monoid.ord ekmett@gmail.com**20090325083138] { hunk ./Data/Monoid/Ord.hs 27 +import Control.Functor.Pointed hunk ./Data/Monoid/Ord.hs 41 +instance Functor Max where + fmap f (Max a) = Max (f a) + +instance Pointed Max where + point = Max + +instance Copointed Max where + extract = getMax + hunk ./Data/Monoid/Ord.hs 60 +instance Functor Min where + fmap f (Min a) = Min (f a) + +instance Pointed Min where + point = Min + +instance Copointed Min where + extract = getMin + hunk ./Data/Monoid/Ord.hs 79 -instance Ord a => Reducer a (MaxPriority a) where - unit = MaxPriority . Just +instance Functor MaxPriority where + fmap f (MaxPriority a) = MaxPriority (fmap f a) + +instance Pointed MaxPriority where + point = MaxPriority . Just hunk ./Data/Monoid/Ord.hs 101 -instance Ord a => Reducer a (MinPriority a) where - unit = MinPriority . Just +instance Functor MinPriority where + fmap f (MinPriority a) = MinPriority (fmap f a) + +instance Pointed MinPriority where + point = MinPriority . Just hunk ./dist/doc/html/monoids/Data-Monoid-Ord.html 335 +>Functor MaxPointed MaxCopointed MaxFunctor MinPointed MinCopointed MinOrd a => Reducer a (Functor a)Pointed MaxPriorityOrd a => Reducer a (Functor a)Pointed MinPriorityOrd a => Reducer a (MinPriority a)Ord a => Reducer a (MaxPriority a)import Data.Monoid.Reducer (Reducer, unit, Monoid, mappend, mempty) - +import Control.Functor.Pointed +import Data.Monoid.Reducer (Reducer, unit, Monoid, mappend, mempty) hunk ./dist/doc/html/monoids/src/Data-Monoid-Ord.html 38 --- | The 'Monoid' @('max','minBound')@ -newtype Max a = Max { getMax :: a } deriving (Eq,Ord,Show,Read,Bounded) - -instance (Ord a, Bounded a) => Monoid (Max a) where - mempty = Max minBound - mappend = max - -instance (Ord a, Bounded a) => Reducer a (Max a) where - unit = Max - --- | The 'Monoid' given by @('min','maxBound')@ -newtype Min a = Min { getMin :: a } deriving (Eq,Ord,Show,Read,Bounded) - -instance (Ord a, Bounded a) => Monoid (Min a) where - mempty = Min maxBound - mappend = min + +-- | The 'Monoid' @('max','minBound')@ +newtype Max a = Max { getMax :: a } deriving (Eq,Ord,Show,Read,Bounded) + +instance (Ord a, Bounded a) => Monoid (Max a) where + mempty = Max minBound + mappend = max + +instance (Ord a, Bounded a) => Reducer a (Max a) where + unit = Max + +instance Functor Max where + fmap f (Max a) = Max (f a) + +instance Pointed Max where + point = Max hunk ./dist/doc/html/monoids/src/Data-Monoid-Ord.html 55 -instance (Ord a, Bounded a) => Reducer a (Min a) where - unit = Min +instance Copointed Max where + extract = getMax hunk ./dist/doc/html/monoids/src/Data-Monoid-Ord.html 58 --- | The 'Monoid' @('max','Nothing')@ over @'Maybe' a@ where 'Nothing' is the bottom element -newtype MaxPriority a = MaxPriority { getMaxPriority :: Maybe a } deriving (Eq,Ord,Show,Read) +-- | The 'Monoid' given by @('min','maxBound')@ +newtype Min a = Min { getMin :: a } deriving (Eq,Ord,Show,Read,Bounded) hunk ./dist/doc/html/monoids/src/Data-Monoid-Ord.html 61 -instance Ord a => Monoid (MaxPriority a) where - mempty = MaxPriority Nothing - mappend = max +instance (Ord a, Bounded a) => Monoid (Min a) where + mempty = Min maxBound + mappend = min hunk ./dist/doc/html/monoids/src/Data-Monoid-Ord.html 65 -instance Ord a => Reducer (Maybe a) (MaxPriority a) where - unit = MaxPriority +instance (Ord a, Bounded a) => Reducer a (Min a) where + unit = Min hunk ./dist/doc/html/monoids/src/Data-Monoid-Ord.html 68 -instance Ord a => Reducer a (MaxPriority a) where - unit = MaxPriority . Just +instance Functor Min where + fmap f (Min a) = Min (f a) hunk ./dist/doc/html/monoids/src/Data-Monoid-Ord.html 71 --- | The 'Monoid' @('min','Nothing')@ over @'Maybe' a@ where 'Nothing' is the top element -newtype MinPriority a = MinPriority { getMinPriority :: Maybe a } deriving (Eq,Show,Read) +instance Pointed Min where + point = Min hunk ./dist/doc/html/monoids/src/Data-Monoid-Ord.html 74 -instance Ord a => Ord (MinPriority a) where - MinPriority Nothing `compare` MinPriority Nothing = EQ - MinPriority Nothing `compare` _ = GT - _ `compare` MinPriority Nothing = LT - MinPriority (Just a) `compare` MinPriority (Just b) = a `compare` b +instance Copointed Min where + extract = getMin + +-- | The 'Monoid' @('max','Nothing')@ over @'Maybe' a@ where 'Nothing' is the bottom element +newtype MaxPriority a = MaxPriority { getMaxPriority :: Maybe a } deriving (Eq,Ord,Show,Read) hunk ./dist/doc/html/monoids/src/Data-Monoid-Ord.html 80 -instance Ord a => Monoid (MinPriority a) where - mempty = MinPriority Nothing - mappend = min +instance Ord a => Monoid (MaxPriority a) where + mempty = MaxPriority Nothing + mappend = max hunk ./dist/doc/html/monoids/src/Data-Monoid-Ord.html 84 -instance Ord a => Reducer (Maybe a) (MinPriority a) where - unit = MinPriority +instance Ord a => Reducer (Maybe a) (MaxPriority a) where + unit = MaxPriority hunk ./dist/doc/html/monoids/src/Data-Monoid-Ord.html 87 -instance Ord a => Reducer a (MinPriority a) where - unit = MinPriority . Just +instance Functor MaxPriority where + fmap f (MaxPriority a) = MaxPriority (fmap f a) + +instance Pointed MaxPriority where + point = MaxPriority . Just + +-- | The 'Monoid' @('min','Nothing')@ over @'Maybe' a@ where 'Nothing' is the top element +newtype MinPriority a = MinPriority { getMinPriority :: Maybe a } deriving (Eq,Show,Read) + +instance Ord a => Ord (MinPriority a) where + MinPriority Nothing `compare` MinPriority Nothing = EQ + MinPriority Nothing `compare` _ = GT + _ `compare` MinPriority Nothing = LT + MinPriority (Just a) `compare` MinPriority (Just b) = a `compare` b + +instance Ord a => Monoid (MinPriority a) where + mempty = MinPriority Nothing + mappend = min + +instance Ord a => Reducer (Maybe a) (MinPriority a) where + unit = MinPriority + +instance Functor MinPriority where + fmap f (MinPriority a) = MinPriority (fmap f a) + +instance Pointed MinPriority where + point = MinPriority . Just }