3 Dec 17:34
Re: Proposal: Max and Min for Monoid (ticket # 1952)
Isaac Dupree <isaacdupree <at> charter.net>
2007-12-03 16:34:30 GMT
2007-12-03 16:34:30 GMT
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
RSS Feed