develooper Front page | perl.perl5.porters | Postings from July 2020

Re: Types in Cor (and Perl)

Thread Previous | Thread Next
Paul "LeoNerd" Evans
July 14, 2020 12:04
Re: Types in Cor (and Perl)
Message ID:
On Tue, 14 Jul 2020 07:29:28 +0000 (UTC)
Ovid via perl5-porters <> wrote:

> The exact semantics and interface of TYPE and ATTRS are still
> evolving.  TYPE may be a bareword, a constant declared with "use
> constant", or "__PACKAGE__".

> So
> there's already some behavior attached to it and I was concerned
> about hijacking that behavior for something else and possibly
> breaking existing code.

Some other core folks might correct me here, but it is my vague
recollection that, besides needing to be a valid package name, there
isn't actually any behaviour currently assigned by core perl to that

So while you can

  package A::Typename;

  my A::Typename $var;

in practice nothing changes if you do that.

That said I would still caution against using this syntax for that
purpose, precisely because it only allows package names whereas we are
likely to want to specify type names - such type names could be
"behaves like an integer"

  $ perl -e 'my aninttype $var'
  No such class aninttype at -e line 1, near "my aninttype"

Finally, I would prefer not to have to complicate grammars in lots of
other places (`has` slots, sub signatures) by simply juxtaposing an
optional typename into the syntax. Far nicer are the ideas that
involve a definite "introduction" keyword, such as an `:is` attribute.

Given a choice between

  my inttype $x;

  my $x :is(int);  # or some other keyword name/syntax to be bikeshedded

I would definitely prefer the second.

Paul "LeoNerd" Evans      |  |

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About