develooper Front page | perl.perl5.porters | Postings from May 2023

Native data checking in Perl

Thread Next
May 17, 2023 08:18
Native data checking in Perl
Message ID:
Hi all,

I’ve been reading through past P5P messages to get a better sense of what
the porters are willing to accept for declaring “types.” I’ll use the term
data “checks” to avoid confusion about type systems.

For a few months, Damian and I have been hashing out a system of checks for
Perl. In particular, we looked at some of the most popular solutions:
Moo/se and Type::Tiny (working within Perl’s constraints), and also Dios an
Zydeco (working to extend Perl’s constraints), plus Raku and some
diversions into other languages.

Unfortunately, Damian deeply regrets that, for personal reasons, he is
unable to continue to work on the project, but is still wholeheartedly in
favor of its stated goals.

At present, there’s a working implementation in a private repo and we
support things like this:

    sub foo :returns(ARRAY[INT]) ( $max_size :of(UINT) ) {...}
    my $count :of(INT) = 0;

In fact, we support a lot more than that and have almost 200K tests
passing, though it's still very much alpha.

In reading P5P and other discussions, it was pleasant to see that there’s
little objection to the notion of checks, but the disagreements largely
arise over syntax and then discussion dies down again. In sharing our work
privately with others, the strongest objection has been the syntax. People
want this (punting on return values):

    sub foo ( UInt $max_size ) returns ArrayRef[Int] {...}
    my Int $count = 0;

Or this:

    sub foo ( $max_size is Uint ) returns ArrayRef[Int] {...}
    my $count is Int = 0;

Or something else entirely.

Our proposal used attributes simply because we were concerned that P5P
would reject the my Dog $spot syntax (and I like the attribute syntax)
because it’s already taken (though not frequently used). However, given the
feedback, I think this didn’t need to be a concern.

Can we discuss this? I think the *semantics* are largely in place. It’s the
*syntax* where things keep breaking down. If we can find an agreed syntax,
I can take the existing work and write up a spec (that’s actually the hard
part, but most of it’s done, pending syntax changes).

The design “the thing and hand it over” worked for Corinna. This will be a
much more important change, but it can work here, too.


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