Bounded and floating types
conal at conal.net
Tue Dec 4 15:45:43 EST 2007
Thanks. That's exactly what I've done:
-- | Wrap a type into one having new least and greatest elements,
-- preserving the existing ordering.
data AddBounds a = MinBound | NoBound a | MaxBound
deriving (Eq, Ord, Read, Show)
instance Bounded (AddBounds a) where
minBound = MinBound
maxBound = MaxBound
Looks like a generally useful tool. Is there any interest in seeing it
added to a standard lib?
On Dec 4, 2007 4:46 AM, Henning Thielemann <lemming at henning-thielemann.de>
> On Mon, 3 Dec 2007, Conal Elliott wrote:
> > I'm using the bounds for event occurrence times. Or, from another
> > for times associated with when values can become known. Pure values
> > time minBound, while eternally unknowable values (non-occurring events)
> > time maxBound. Hm. Now that I put it that way, I realize that I don't
> > to use existing minBound and maxBound if they're finite. (My event
> > are temporally polymorphic.) I'm mainly interested in Float/Double
> > which have infinities in practice but apparently not guaranteed by the
> > language standard. I guess I'll either (a) bake in Double (temporally
> > monomorphic) and rely on infinities not guaranteed by the standard, or
> > keep temporal polymorphism and add infinities to time parameter. For
> > (b).
> Since you cannot rely on the existence of an infinity value for a floating
> point type with a particular behaviour - you can simply define you own
> data InfinityClosure a = NegativeInfinity | Finite a | PositiveInfinity
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libraries