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

Re: Types in Cor (and Perl)

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
July 14, 2020 12:04
Subject:
Re: Types in Cor (and Perl)
Message ID:
20200714130415.302de948@shy.leonerd.org.uk
On Tue, 14 Jul 2020 07:29:28 +0000 (UTC)
Ovid via perl5-porters <perl5-porters@perl.org> 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
information.

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

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About