On Mon, May 30, 2005 at 18:51:19 +0200, "TSa (Thomas Sandla)" wrote:
> class Set does Array {...}
I don't like this... A set is just a simple example... What if I
want something sillier?
My question is really:
"How do I make sub foo returns $computable"
And how do I make this friendly to the compiler (declarable), so
that type inferrence like behavior can be enforced
> and use the corresponding sigil for variables:
>
> my @a is Set;
This works with your example, but it makes more sense if it's only a
derefernce-overload op.
A set and an array are distinct.. Sets are unordered, arrays are
ordered by definition. Sets know how to do set ops on each other,
arrays don't...
This becomes very problematic when you have several methods for
extraction - how do you distinct a method that returns the contained
type from another? An array can only be flattenned to a list, and
have subscripts extracted Other extractions are generic to list
data (grep, etc), and do not apply to things like Sets.
> My guess is that there is a Parrot level class that implements
> the level of indirection needed by Perl6 sigiled variables. If
> it weren't for Perl5 referential legacy it could easily be called
> Ref.
Please explain this idea in more detail.
>
> This container base class might just implement the basic machinery needed
> to make your Set available as container. But once again I don't know
> about the mapping to sigils and the set of supported operations.
STL (C++) has some nice ideas, if you consider templates and so
forth nice. In perl 6 I wouldn't like to see that, because it would
hinder flexibility, but basically what you do there is
typedef map FooMap; // garbage fields omitted
And then your FooMap is usable as a container of Foos. But since we
have dynamic runtime things, and much more complicated operations
with mixins, roles, MMD, and we're still trying to optimize all of
these (or rather expose the data to help parrot optimize it for us),
and more importantly help those who want safe programs (or safe
parts of programs) with a little more effort get that.
This is a hard conflict to deal with.
What we need to define is the possibility that a declaration:
my Set of Foo $set;
Affects the 'returns' trait of some methods
$set.members; # we now know it's Foo, because that's what $set is `of`
Aye?
> Hmm, the usual thing the implementation of a container requires
> is a minimal interface needed from the elements for the container
> to do what it is supposed to do.
You mean like generic methods for a container?
> In the case of a set this requirement is to check the identity of
> elements---basically like the keys of hashes.
True, but there are more complicated containers out there... =)
> Well, I think there are the concrete list types Eager and Lazy,
> so it could be a simple 'Lazy of Int'. In a signature you use the
> slurpiness indicator * which I presume is available in :() as well.
> So a list of Int might be :(*Int) and a recurring tuple type might
> be :(*(Int,Str)).
That seems pretty nice, although not aesthetically appealing.
--
() Yuval Kogman <[EMAIL PROTECTED]> 0xEBD27418 perl hacker &
/\ kung foo master: /me whallops greyface with a fnord: neeyah!!!
pgpZ5w5VFtv0l.pgp
Description: PGP signature