On Sat, Nov 05, 2005 at 01:55:11AM +0100, TSa wrote:
: Larry Wall wrote:
: >The notion of constraints or limitations is already conveyed by
: >"where", and some subtypes may just be aliases.
: Wouldn't 'bound' work? Perhaps combined with 'on':
:   bound SmallInt on Int where { 0 < $_ < 100 };
: and
:   Int bound SmallInt where { 0 < $_ < 100 };
: or is 'bound of' proper english?

It doesn't really resonate for a native speaker.

: And perhaps ranges could be allowed in the type slot
:   my 1..100 $x;
:   $x = 101; # type error
: And with enums
:   my enum <a b c d> $x;
:   $x = g; # error unless &g exists and returns a type
:           # structurally equal to enum <a b c d> which
:           # might be the same as 0..3

It starts getting a bit special-casey to allow rvalue-ish expressions
in the type slot.  Now that we have a type sigil, maybe:

    my ^(1..100) $x
    my ^(enum <a b c d>) $x;

: > Plus, as we've defined
: >them above, subtypes are the most generic type you can name in Perl.
: Ahm, why? They just add predicates that have to hold true. The only
: genericity I see is that a subtype declaration doesn't need anything
: remotely implementation like. Not even the constraint type must be
: there yet:
:   subtype Blahh of ::Fasel; # declaration of Fasel deferred
:   my Blahh $b .=new; # compiles for now, but needs ::Fasel eventually
: BTW, could we restrict predicates to deal with the state available through
: the type/kind that is constraint? This would allow compile time calculations
: of contraint subsumption, type entailment and of upper and lower bounds.

I wasn't using the term "generic" in a type-theoretic sense.  Rather,
I was calling them generic in an operational sense, which you just
demonstrated.  You can turn any other type into a "subtype" alias that
adds no additional constraints.  Maybe I should have said the "widest"
type instead.

: Question: does a subtype declaration work only on package-like things
: which are addressed with a :: sigil? Or does your 'potentially
: contravariant' mean that arrow types can be constraint or aliased, as
: well?
:   subtype TakesInt of Sub where { .sig =:= :(Int --> Any) };
:   my TakesInt &foo;
:   foo('a string'); # type error

Hmm, I would read that as declaring that &foo *returns* a TakesInt,
not that &foo *is* a TakesInt.  Just as

    my TakesInt @bar;

declares an array of individual TakesInt elements.

: This might actually produce the strange association of subtype
: with subs and requesting corresponding methodtype, datatype,
: roletype, etc. keywords for other kinds of types.

I really don't know how far it makes sense to drive this.  Mostly I'm
just trying to keep the syntax open enough that the bikeshed doesn't
end up looking like grafitti when we're done.


Reply via email to