On Friday, 27. February 2009 07:42:17 Darren Duncan wrote:
> I was thinking that Perl 6 ought to have a generic interval type that is
> conceptually like Range, in that it is defined using a pair of values of an
> ordered type and includes all the values between those, but unlike Range
> that type is not expected to have discrete consecutive values that can be
> iterated over.

Hmm, it might not be a bad idea to make Interval a subtype of Range
and allow for iteration if that is requested. This allows an Interval
where Range is expected.

The benefit of a dedicated Interval type comes from supporting set
operations (&), (|) etc. which are still unmentioned in S03. BTW,
what does (1..^5).max return? I think it should be 4 because this
is the last value in the Range. Only in 4.7 ~~ 1..^5 does the five
matter. How does ~~ retrieve that information? For open intervals
the .min and .max methods should return the bound outside. Or better,
we should introduce infimum and supremum as .inf and .sup respectively.


> I'm thinking of a Range-alike that one could use with Rat|Num or Instant
> etc, and not just Int etc.  There would be operators to test membership of
> a value in the interval, and set-like operators to compare or combine
> intervals, such as is_inside, is_subset, is_overlap, union, intersection,
> etc.  Such an interval would be what you use for inexact matching and would
> be the result of a ± infix operator or % postfix operator.  Also, as Range
> has a .. constructor, this other type should have something.

Since the Interval type shall be an addition to the Set subsystem I
propose the (..) Interval creation operator together with the open
versions. Admittedly that leaves (^..^) at a lengthy six chars. But
Jon's proposal of setting the by to zero isn't any shorter. Note that
the open versions are more important for Interval than they are for Range
because for Range you can always write it without ^ at the ends.


> Barring a better name coming along, I suggest calling the type "Interval",
> and it would be immutable.

The only other name that comes to mind is RangeSet. But I prefer Interval
because this is the name of the concept in math.


Regards, TSa.
-- 
"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan

Reply via email to