
3 Dec
2007
3 Dec
'07
11:34 a.m.
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. Isaac