cjdoris/Infinity.jl

`Infinite <: Real`?

Opened this issue · 2 comments

Currently Infinite is a subtype of Real. But now we have InfExtendedTime. Should we have Infinite <: Any instead? Options:

  • Leave Infinite <: Real, but also allow Infinite to promote to TimeType.
  • Change Infinite <: Any. This means you can't do arithmetic between Real and Infinite (without adding a lot of methods for +, * etc to promote arguments) but maybe that's not really a problem?
  • Have two infinities: a real one and a time one?

My current proposal:

  • Have Infinite <: Any, with two values and -∞ (aka PosInf and NegInf) as at the moment.
  • Also have InfiniteReal <: Real, with two values PosInfReal and NegInfReal. Promotion between Real and Infinite yields InfiniteReal. Real(∞) is PosInfReal. Promotion between any T<:Real and Infinite or InfiniteReal yields InfExtendedReal{T}. Users should mostly not care about this type, and just need to know about Real(∞), or explicitly promote things.
  • Similarly, have InfiniteTime <: TimeType, PosInfTime, and TimeType(∞).

This way, the user can mostly just use and promotion will do the right thing --- e.g. Interval(3,∞) will promote to InfExtendedReal{Int}. But you'll need to do 1+Real(∞) instead of 1+∞ (unless we provide promotion methods for common arithmetic operations).

I realize that T(x) isn't guaranteed to return a T, but I do normally expect it to. Why not just let Real(∞) raise an error?