Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Just reading up on Pike...

13 views
Skip to first unread message

Chris Dutton

unread,
Aug 16, 2002, 1:42:27 AM8/16/02
to perl6-l...@perl.org
.... and this just jumped out at me:

class Foo {
private string|int bar;
static create(string|int newBar) {
bar = newBar;
}
}

In other words, as I understand it, you can type the variable bar as
either an int or a string.

Aside from simply, "my $bar;", will we be able to repeat this behavior
in Perl6 programs?

Let me guess, though, this is one of those instances where I should have
read A1..5 and E1..4 more closely. :-)

Damian Conway

unread,
Aug 16, 2002, 4:41:02 PM8/16/02
to perl6-l...@perl.org
Chris Dutton wrote:
> .... and this just jumped out at me:
>
> class Foo {
> private string|int bar;
> static create(string|int newBar) {
> bar = newBar;
> }
> }
>
> In other words, as I understand it, you can type the variable bar as
> either an int or a string.
>
> Aside from simply, "my $bar;", will we be able to repeat this behavior
> in Perl6 programs?

Well, I'm still hopeful Larry will approve superpositions. In which case,
since types in Perl 6 are first-class, you would be able to write
the same thing something like:


class Foo {
attr any(str,int) $bar;

method SETUP(any(str,int) $newBar) {
$bar = $newBar;
}
}

Damian

Luke Palmer

unread,
Aug 16, 2002, 5:38:21 PM8/16/02
to Damian Conway, perl6-l...@perl.org
> Well, I'm still hopeful Larry will approve superpositions. In which case,
> since types in Perl 6 are first-class, you would be able to write
> the same thing something like:
>
>
> class Foo {
> attr any(str,int) $bar;
>
> method SETUP(any(str,int) $newBar) {
> $bar = $newBar;
> }
> }
>
> Damian

I want superpositions too :). But, what would this mean?

my all(str, int) $foo;
#...

Luke

Nicholas Clark

unread,
Aug 16, 2002, 7:12:16 PM8/16/02
to dam...@conway.org, fibo...@babylonia.flatirons.org, perl6-l...@perl.org
On Sat, Aug 17, 2002 at 06:41:02AM +1000, Damian Conway wrote:
> Well, I'm still hopeful Larry will approve superpositions. In which case,
> since types in Perl 6 are first-class, you would be able to write
> the same thing something like:
>
>
> class Foo {
> attr any(str,int) $bar;
>
> method SETUP(any(str,int) $newBar) {
> $bar = $newBar;
> }
> }

But how on earth would you implement such a thing? :-)

On Fri, Aug 16, 2002 at 04:05:04PM -0700, dam...@conway.org wrote:


> On Fri, 16 August 2002, Luke Palmer wrote:
>
> > I want superpositions too :). But, what would this mean?
> >
> > my all(str, int) $foo;
> > #...
>

> That you need some *serious* psychotherapy! ;-)

"Mr Palmer, the doctor is ready to see you now..."

oops, wrong sort of doctor.

Nicholas Clark
--
Even better than the real thing: http://nms-cgi.sourceforge.net/

dam...@conway.org

unread,
Aug 16, 2002, 7:05:04 PM8/16/02
to fibo...@babylonia.flatirons.org, perl6-l...@perl.org
On Fri, 16 August 2002, Luke Palmer wrote:

> I want superpositions too :). But, what would this mean?
>
> my all(str, int) $foo;
> #...

That you need some *serious* psychotherapy! ;-)

Actually, it would mean that $foo can only contain values
whose type is simultaneously C<str> and C<int>. That is, $foo
can only contain something like C<any(1,"str")>.

Damian

Aaron Sherman

unread,
Aug 16, 2002, 10:52:06 PM8/16/02
to Damian Conway, fibo...@babylonia.flatirons.org, Perl6 Language List

So,

my all(str, int) $foo = $!;

would be fine? I'm forgetting what has been said about $! in p6, of
course, but there you have it.


dam...@conway.org

unread,
Aug 17, 2002, 11:48:58 AM8/17/02
to ni...@unfortu.net, fibo...@babylonia.flatirons.org, perl6-l...@perl.org
On Sat, 17 August 2002, Nicholas Clark wrote:


> But how on earth would you implement such a thing? :-)

I imagine that type specifiers require that values assigned to
the corresponding variable satisfy: value.isa(type). Using a
superposition as a type means that the result of that test comes
back as a superposition too. If that returned superposition is
true, the assignment proceeds.

Damian

dam...@conway.org

unread,
Aug 17, 2002, 11:55:52 AM8/17/02
to a...@ajs.com, fibo...@babylonia.flatirons.org, perl6-l...@perl.org
Aaron Sherman wrote:

> So,
>
> my all(str, int) $foo = $!;
>
> would be fine?

I'd expect so.

> I'm forgetting what has been said about $!

Typically contains an object with both string and integer conversions.
Whether convertability to both types is enough to satisfy a
superpositional type is an interesting question. I suspect it *is*.

Damian

Trey Harris

unread,
Aug 17, 2002, 12:21:36 PM8/17/02
to dam...@conway.org, a...@ajs.com, fibo...@babylonia.flatirons.org, perl6-l...@perl.org
In a message dated Sat, 17 Aug 2002, dam...@conway.org writes:
> [$!] Typically contains an object with both string and integer

> conversions. Whether convertability to both types is enough to satisfy a
> superpositional type is an interesting question. I suspect it *is*.

Then I'd assume that multiple inheritance of both types would also
conform? So if $! is Errno, where class Errno is str is int (or is that
Errno is str, int?), that would work too?

Wow. There's more than one way to do it--even static(-ish) typing. Who
woulda thunk it. :-)

Trey

Andy Wardley

unread,
Aug 18, 2002, 6:14:11 AM8/18/02
to perl6-l...@perl.org, dam...@conway.org
dam...@conway.org wrote:
> [...] whose type is simultaneously C<str> and C<int>.

Has any thought yet gone into the builtin Perl types and what they will
be called in Perl 6? Will there be a difference between the C<ref()> of
something and the type(s) that C<isa()> returns?

In keeping with the lower case C<str> and C<int> examples above, will
the builtin Perl types ARRAY, HASH, SCALAR, etc., have lower case
equivalents? Is this an opportunity to replace the ill-named C<ARRAY>
with C<LIST>, or rather C<list>? (I'm sure I've heard Larry say that,
with hindsight, he wishes he had spelled 'ARRAY' as 'LIST', so I hope
I'm not speaking out of line). Could we also come up with a snappier
name than C<SCALAR> to denote a single item reference? Perhaps C<item>,
or just plain C<ref>?

Presumably, C<ref()> would continue to work as it always has, while C<isa()>
returns the most specific type for a variable when called in scalar context,
or a list of the type and all supertypes when called in list context.

var ref isa
-------------------------------------------------
\@foo ARRAY list / ref
\%bar HASH hash / ref
\$baz SCALAR item / ref
my Dog $spot Dog Dog / Animal / obj / ref
"blah blah" - str
3.14 - num
42 - int / num

The only RFC I can find that's related is 224, where Damian talks about
making ref() more magical. http://dev.perl.org/rfc/224.pod

Any other thoughts on this floating around out there?

A

Damian Conway

unread,
Aug 18, 2002, 2:32:32 PM8/18/02
to perl6-l...@perl.org
Trey Harris wrote:


> Then I'd assume that multiple inheritance of both types would also
> conform?

Yes.


> So if $! is Errno, where class Errno is str is int

> that would work too?

I very much doubt you'll be able to inherit from the builtin types.


> (or is that Errno is str, int?),

Multiple inheritance will be:

class Derived is Base1 is Base2

or possibly:

class Derived is Base1 Base2


Damian

Piers Cawley

unread,
Aug 19, 2002, 4:33:36 AM8/19/02
to Damian Conway, perl6-l...@perl.org
Damian Conway <dam...@conway.org> writes:
> Multiple inheritance will be:
>
> class Derived is Base1 is Base2
>
> or possibly:
>
> class Derived is Base1 Base2

How about class Derived is all(Base1, Base2);

--
Piers

"It is a truth universally acknowledged that a language in
possession of a rich syntax must be in need of a rewrite."
-- Jane Austen?

Richard Soderberg

unread,
Aug 19, 2002, 5:39:38 PM8/19/02
to
fibo...@babylonia.flatirons.org (Luke Palmer) wrote in message news:<Pine.LNX.4.33.020816...@babylonia.flatirons.org>...

> > Well, I'm still hopeful Larry will approve superpositions. In which case,
> > since types in Perl 6 are first-class, you would be able to write
> > the same thing something like:

> I want superpositions too :). But, what would this mean?


>
> my all(str, int) $foo;
> #...

Perhaps it would be a way to store both str AND int values in $foo?
I've been wondering how Perl6 will let me do that, anyways (cf.
p5/Scalar::Util).

R.

Damian Conway

unread,
Aug 21, 2002, 1:56:46 PM8/21/02
to Piers Cawley, perl6-l...@perl.org
Piers Cawley wrote:
> Damian Conway <dam...@conway.org> writes:
>
>>Multiple inheritance will be:
>>
>> class Derived is Base1 is Base2
>>
>>or possibly:
>>
>> class Derived is Base1 Base2
>
>
> How about class Derived is all(Base1, Base2);

Close, but no cigar. You meant:

class Derived is any(Base1, Base2);

"Why" is left as an exercise for the reader.

Damian

0 new messages