Being able to type the elements in containers was considered a major
problem in Java for years before they added generics. And the whole point
of having a computer is to have it do repetitive things, e.g. loop over a
bunch of stuff and do the same thing to all of it. How is this an
"exaggerated" use of containers? Why have the language feature at all if
it's too clunky for people to use it?

On Jan 7, 2017 8:42 AM, "Moritz Lenz" <mor...@faui2k3.org> wrote:

> Hi,
>
> On 07.01.2017 12:45, Fernando Santagata wrote:
> > Hello,
> >
> > I have a function like this:
> >
> > sub test(Str :$format, :@filter)
> > {
> >   say $format;
> >   say @filter;
> > }
> >
> > and I wish to have a stricter type control over the second parameter.
> >
> > The natural way to do it seemed this:
> >
> > sub test(Str :$format, Array[Str] :$filter)
> > {
> >   say $format;
> >   say $filter;
> > }
> >
> > but then I have to call it this way:
> >
> > test format => 'gnutar', filter => Array[Str].new('gzip', 'uuencode');
> >
> > Is there a less cumbersome way to do it?
>
> As you have discovered, you need to be explicit about the type of the
> argument that's passed in.
>
> You can use anonymous variables to write an Array[Str] more compact:
>
> test format => 'gnutar', filter => my Str @ = 'gzip', 'uuencode';
>
> or even
>
> test format => 'gnutar', filter => my Str @ = <gzip uuencode>;
>
> My general advise is to not exaggerate the usage of container types.
> Think of Perl 6 as a dynamically typed language, and only add types
> where they make life easier for everybody involved.
>
> Cheers,
> Moritz
>
> --
> Moritz Lenz
> https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/
>

Reply via email to