Proposal: Max and Min for Monoid (ticket # 1952)

Isaac Dupree isaacdupree at
Mon Dec 3 11:34:30 EST 2007

Ross Paterson wrote:
> Funny, I was thinking of proposing a Max type that adjoined a synthetic
> identity, as we did in the finger tree paper:
> data Max a = NoMax | Max a
> 	deriving (Eq, Ord, Read, Show)
> instance Ord a => Monoid (Max a) where
> 	mempty = NoMax
> 	NoMax `mappend` b = b
> 	a `mappend` NoMax = a
> 	Max x `mappend` Max y = Max (x `max` y)
> and similarly for Min.  One could even define
> 	getMax :: Bounded a => Max a -> a
> 	getMax NoMax = minBound
> 	getMax (Max x) = x

I was thinking you could get that with some version of the (Maybe (Max 
a)) Monoid, but you are right: your version doesn't require (a) to be 
Bounded, thus works with Integers etc.


More information about the Libraries mailing list