Jon, I like all of your stated ideas in general. I also don't care about the postfix %; that was just a concept example pulled from the inexact comparison thread. The idea of using zero is also appropriate conceptually with shades of how calculus works. I actually prefer the existing Range constructor of .. visually, as long as it works unambiguously in both roles. It does make a lot of sense for Range to do Set. So we just need some way, probably a role, to distinguish whether this broader definition of a set is enumerable or not on a case by case basis. When talking about any/all/etc this also means that junctions would have to work with the non-enumerable set. -- Darren Duncan

Jon Lang wrote:
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.

Note that smart-matching currently treats Range as an interval.  The
question is whether we need intervals for any other purpose.  If we
do, perhaps we could still press Range into service, but indicate that
there are no discrete consecutive values by saying something like
":step(0)" (where "0" is being used to mean "arbitrarily small" rather
than truly zero).  This would disable some uses (such as using it as a
looping mechanism or counting the number of items that it
encompasses), but might enable some others.

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.

(Not postfix:<%>, please; that should produce a single value by itself.)

Instead of saying "set-like operators", etc., why not just say that
Interval does Set?  The conceptual difference would be that it is a
set of continuous values rather than a set of discrete values... This
should also allow you to do things like "any($i)" (where $i is an
Interval).  Indeed, a Set membership test strikes me as being
equivalent to smart-matching an any-junction of the Set.

As for a constructor: as hinted above, ".." could probably pull
double-duty as a constructor for both Ranges and Intervals, based on
the spacing (or absence thereof) between members.  One _might_ even go
so far as to say that :step (or whatever it's called) defaults to 1
for discrete types (such as Int) and to 0 for continuous types (such
as Rat); so "0 .. 1" and "0.0 .. 1.0 :step(1)" would each create a
two-item Range, while "0 .. 1 :step(0)" and "0.0 .. 1.0" would each
create an Interval.


Reply via email to