I encountered exactly this issue in my use of the Max & Min monoids in Reactive. I wanted to allow already-bounded types to use their own minBound for Max and maxBound for Min, and also allow unbounded types to be used. So, rather than entangling bound addition with Max & Min, I defined AddBounds type wrapper, which is *orthogonal* to Max & Min. If your type is already Bounded, then use my simple Max & Min wrappers directly. If not (as in Reactive's use), compose Max or Min with AddBounds.<br>
<br>I'm sorry I didn't think to mention this useful composition the Max & Min trac ticket.<br><br> - Conal<br><br><div class="gmail_quote">On Thu, Sep 23, 2010 at 10:47 AM, Gregory Collins <span dir="ltr"><<a href="mailto:greg@gregorycollins.net">greg@gregorycollins.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">Felipe Lessa <<a href="mailto:felipe.lessa@gmail.com">felipe.lessa@gmail.com</a>> writes:<br>
> On Thu, Sep 23, 2010 at 12:58 PM, Jake McArthur <<a href="mailto:jake.mcarthur@gmail.com">jake.mcarthur@gmail.com</a>> wrote:<br>
><br>
</div><div class="im">>>> -- | Ordered monoid under 'max'.<br>
>>> newtype Max a = Max { getMax :: a }<br>
>>> deriving (Eq, Ord, Read, Show, Bounded)<br>
>>><br>
>>> instance (Ord a, Bounded a) => Monoid (Max a) where<br>
>>> mempty = Max minBound<br>
>>> Max a `mappend` Max b = Max (a `max` b)<br>
><br>
> Why should we prefer this monoid over<br>
><br>
>> data Max a = Minimum | Max a<br>
>> deriving (Eq, Ord, Read, Show)<br>
>><br>
>> instance Ord a => Monoid (Max a) where<br>
>> mempty = Minimum<br>
>> Minimum `mappend` x = x<br>
>> x `mappend` Minimum = x<br>
>> Max a `mappend` Max b = Max (a `max` b)<br>
<br>
</div>You're right, the original wouldn't fly because there are unbounded<br>
types (like Integer) that you'd like to be able to use with Max/Min.<br>
<br>
Rather than your proposal I would suggest that Max/Min mirror<br>
the existing First/Last, namely:<br>
<br>
newtype Max a = Max { getMax :: Maybe a }<br>
<div class="im"> deriving (Eq, Ord, Read, Show)<br>
<br>
instance (Ord a) => Monoid (Max a) where<br>
</div> mempty = Max Nothing<br>
mappend = max<br>
<br>
G<br>
<font color="#888888">--<br>
Gregory Collins <<a href="mailto:greg@gregorycollins.net">greg@gregorycollins.net</a>><br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
</div></div></blockquote></div><br>