
How would I introduce number classes that are extended with plus and minus infinity? I'd like to have polymorphism over these new classes, something like a signature f :: (Real a, Extended a b) => b -> b which clearly is not part of the current syntax, but I hope you get the picture. What are the elegant ways of doing this? Somewhat related (I think), I have a class of dyadic numbers, it is clearly in Num and Real, but not in Fractional. Now, I would like to have intervals, both dyadic and rational, providing operations like lower and upper end point, centre, diameter, the partial order of interval inclusion, and membership for a dyadic/rational number. All these operations can be computed on dyadic numbers (only division by 2 is needed). Could I make the rational numbers belong to a class of "averageable numbers" or something like that so that I can get actual dyadic numbers returned when they happen to be dyadic? Jens

On Mon, May 16, 2005 at 09:26:07PM +0200, Jens Blanck wrote:
How would I introduce number classes that are extended with plus and minus infinity? I'd like to have polymorphism over these new classes, something like a signature
f :: (Real a, Extended a b) => b -> b
which clearly is not part of the current syntax, but I hope you get the picture. What are the elegant ways of doing this?
How about f :: Real a => Extended a -> Extended a Double and Float already include -Infinity and +Infinity: Prelude> -(1/0) :: Double -Infinity Best regards Tomasz

How would I introduce number classes that are extended with plus and minus infinity? I'd like to have polymorphism over these new classes, something like a signature
f :: (Real a, Extended a b) => b -> b
which clearly is not part of the current syntax, but I hope you get the picture. What are the elegant ways of doing this?
How about f :: Real a => Extended a -> Extended a
Double and Float already include -Infinity and +Infinity:
Prelude> -(1/0) :: Double -Infinity
Not quite what I had in mind. I'd like to have extended integers and extended rationals, and possibly extended dyadic numbers. So I can't have just a single type ExtendedRational (unless I'm prepared to do some ugly coersing). Jens

On Tue, May 17, 2005 at 01:13:17PM +0200, Jens Blanck wrote:
How would I introduce number classes that are extended with plus and minus infinity? I'd like to have polymorphism over these new classes, something like a signature
f :: (Real a, Extended a b) => b -> b
which clearly is not part of the current syntax, but I hope you get the picture. What are the elegant ways of doing this?
How about f :: Real a => Extended a -> Extended a
Not quite what I had in mind. I'd like to have extended integers and extended rationals, and possibly extended dyadic numbers. So I can't have just a single type ExtendedRational (unless I'm prepared to do some ugly coersing).
You're missing the point. Try:
data Extended a = PlusInf | NegInf | Finite a
Peace, Dylan
participants (3)
-
dpt@lotus.bostoncoop.net
-
Jens Blanck
-
Tomasz Zielonka