Yuval Kogman wrote:
my Set of Int $s = Set.new; # is this how you call it?
This whole thing depends on how hard-wired the first level container implementation is. There is either a loose or very strict mapping from sigils to container types: $ --> Scalar/Item @ --> Array % --> Hash & --> Code If things like 'my $x is Array' work, then using your set class is straight forward. If Item, Array, Hash and Code are sigil-types then you must compose them into your class: class Set does Array {...} and use the corresponding sigil for variables: my @a is Set; The 'of'-part might be handled by the compiler generically. But I don't know where that type contraint is actually stored nor how it is invoked. It might just be composed implicitly. 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.
Or do we say class Set is Container { # magical? method members returns returns ... # some facility by Container? }
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.
Even if the way to implement this is as thin as C++ templates, that is, we'll have to define a container of some type, and define the type as a complex thing, instead of defining a container of complex things, it's still better than nothing.
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. In the case of a set this requirement is to check the identity of elements---basically like the keys of hashes.
This brings me to another issue - can I say what type the elements of a list has, without putting it into a typed array?
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)). -- TSa (Thomas Sandlaß)