Proposal for Max/Min Monoids Trac ticket 3036

Here is the ticket information.
Will
---------- Forwarded message ----------
From: GHC

I like the Min/Max monoids, and the possibility of adding something
like AddBounds (although I'd prefer a name like "Bounded"; "Bounded
Integer" reads better than "AddBounds Integer").
One possible snag is that, so far as I know, there's no explicit
requirement that a type that instantiates Ord and Bounded should
satisfy the laws,
min maxBound a = a = min a maxBound
max minBound a = a = max a minBound
We're just assuming (reasonably) that instances will always work out
that way. (Although, I guess we're making the same assumption with Sum
and Prod.)
--
Dave Menendez

2009/2/20 David Menendez
I like the Min/Max monoids, and the possibility of adding something like AddBounds (although I'd prefer a name like "Bounded"; "Bounded Integer" reads better than "AddBounds Integer").
We already have a Bounded typeclass, so things would get confusing. How about BoundsAdded Integer?
One possible snag is that, so far as I know, there's no explicit requirement that a type that instantiates Ord and Bounded should satisfy the laws,
min maxBound a = a = min a maxBound max minBound a = a = max a minBound
We're just assuming (reasonably) that instances will always work out that way. (Although, I guess we're making the same assumption with Sum and Prod.)
You could do something like class (Bounded a, Ord a) => BoundedOrd a where minB :: a -> a -> a minB a b | b == maxBound = a | a == maxBound = b | (a == minBound) || (b == minBound) = minBound | otherwise = min a b maxB :: a -> a -> a maxB a b | b == minBound = a | a == minBound = b | (a == maxBound) || (b == maxBound) = maxBound | otherwise = max a b And have the types inside Min and Max monoids need to be instances of this type. It depends how much we are trusting the implementors of min and max... It also doesn't stop people reimplementing them, perhaps we'll have to wait for conal's type class morphisms (I haven't fully digested these yet)? Will Pearson

On Fri, Feb 20, 2009 at 2:57 PM, William Pearson
2009/2/20 David Menendez
: I like the Min/Max monoids, and the possibility of adding something like AddBounds (although I'd prefer a name like "Bounded"; "Bounded Integer" reads better than "AddBounds Integer").
We already have a Bounded typeclass, so things would get confusing. How about BoundsAdded Integer?
OrInfinity? :-) I suppose Extended -- as in "extended real number" -- would not make the intent clear enough... -b

On 2009-02-21, Benja Fallenstein
On Fri, Feb 20, 2009 at 2:57 PM, William Pearson
wrote: 2009/2/20 David Menendez
: I like the Min/Max monoids, and the possibility of adding something like AddBounds (although I'd prefer a name like "Bounded"; "Bounded Integer" reads better than "AddBounds Integer").
We already have a Bounded typeclass, so things would get confusing. How about BoundsAdded Integer?
OrInfinity? :-)
I suppose Extended -- as in "extended real number" -- would not make the intent clear enough...
Borrowing from topology, "completion", or "compactified" suggest themselves, but I don't think they're clear enough in this context. WithBounds, BoundsAdded, or Bounded seem clear enough. I personally am not too concerned with the overlap with the Bounded typeclass. In fact, I think that agreeing is a nice concurrence of terminology. -- Aaron Denney -><-

Aaron Denney wrote:
Borrowing from topology, "completion", or "compactified" suggest themselves, but I don't think they're clear enough in this context. WithBounds, BoundsAdded, or Bounded seem clear enough. I personally am not too concerned with the overlap with the Bounded typeclass. In fact, I think that agreeing is a nice concurrence of terminology.
I think "Bounded" is outright misleading here. It *adds* an upper bound and a lower bound, even if they already exist. Bounded Integer -- well, okay Bounded Int -- hey, Int is already bounded, but this adds more bounds. or for a type that's conceptually more bounded to start with, Bounded Natural -- MinBound then is not 0, it's less than 0. Bounded (Bounded X) -- adds two layers of bounds; it's not idempotent. -Isaac
participants (5)
-
Aaron Denney
-
Benja Fallenstein
-
David Menendez
-
Isaac Dupree
-
William Pearson