HaloO,

Larry Wall wrote:
At the moment, I think the weakest word choice is "subtype".
People from certain cultures will confuse subtypes with subclasses.


Not to mention submethods and subroutines!


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? 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


 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.

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

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


So maybe we should go with "type"...which is yet another thing I've
waffled on repeatedly...

HiHi.
--

Reply via email to