Similarly, I'm using the following to get around type parameters that don't provide Bounded:

data AddBounds a = MinBound | NoBound a | MaxBound
  deriving (Eq, Ord, Read, Show)

instance Bounded (AddBounds a) where
  minBound = MinBound
  maxBound = MaxBound


On Dec 2, 2007 3:25 PM, Ross Paterson <ross@soi.city.ac.uk> wrote:
On Sun, Dec 02, 2007 at 09:57:50AM -0800, Conal Elliott wrote:
> My proposed addition:
>
> -- | Ordered monoid under 'max'.
> newtype Max a = Max { getMax :: a }
>       deriving (Eq, Ord, Read, Show, Bounded)
>
> instance (Ord a, Bounded a) => Monoid (Max a) where
>       mempty = Max minBound
>       Max a `mappend` Max b = Max (a `max` b)

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
_______________________________________________
Libraries mailing list
Libraries@haskell.org
http://www.haskell.org/mailman/listinfo/libraries