Mailing List Archive

PPC Elevator Pitch for Perl::Types
# Proposed Perl Changes Elevator Pitch for Perl::Types

This document is the first step in the Proposed Perl Changes process:

https://github.com/Perl/PPCs/blob/main/README.md

Respectfully submitted by the _Perl::Types Committee_:
* Will Braswell (WBRASWELL), Co-Founder & Chairman
* Brett Estrade (OODLER), Co-Founder & 1st Vice Chairman
* Zakariyya Mughal (ZMUGHAL), Co-Founder & 2nd Vice Chairman
* John Napiorkowski (JJNAPIORK)
* Darren Duncan (DUNCAND)
* Nedzad Hrnjica (NHRNJICA)
* Rohit Manjrekar (MANJREKAR)
* Paul Millard (MAGUDAS)
* Joshua Day (HAX)
* Tyler Bird (BIRDTY)
* Robbie Hatley (HATLEYSFT)
* David Warner (WESTBASE)
* Daniel Mera (DMERA)
* Duong Vu (DVU)
* Rajan Shah (RSHAH)

## Here is a problem

Perl lacks sufficient exposure of the already-existing real natural
Perl data types for use by the programmer. This has lead to false
claims that the Perl interpreter "has no data types". This has
also lead to countless programmer-hours spent devising synthetic
or unnatural type systems that rely entirely on fuzzy data guessing
via regular expressions, etc.

Fortunately, the Perl compiler already provides the capability to
expose the underlying real native C data types which can be used
by Perl programmers to incrementally improve performance, eventually
achieving the full native speed of compiled C code. Among other
features, the Perl compiler also enables real natural data type
checking with identical behavior in both dynamic (intrepreted) mode
and static (compiled) mode.

https://metacpan.org/dist/RPerl

The data type subsystem of the Perl compiler is currently in the
process of being extracted and refactored as an independant CPAN
distribution called `Perl::Types`. This distribution provides new,
core capabilities and thus should be included in the Perl core
distribution as a "Dual-Life" module.

https://github.com/Dual-Life

## Here is the syntax that we're proposing

The Perl interpreter already has an unused slot in the grammar for
this very purpose:

`my TYPE $var;`

The Perl interpreter and the Perl compiler already provide the
basic data types to be used in the grammar slot above:

* `boolean` (`SV` when `SvIsBOOL(sv)` is true, new in 5.36)
* `integer` (`IV`)
* `number` (`NV`)
* `string` (`PV`)
* `array` (`AV`) & `arrayref` (`RV(AV)`)
* `hash` (`HV`) & `hashref` (`RV(HV)`)
* user-defined classes

Custom data structures are declared with compound or nested data
types composed from the basic types above, for example:

* `integer::arrayref`
* `integer::arrayref::arrayref`
* `integer::arrayref::hashref`
* `integer::arrayref::arrayref::hashref`
* `string::arrayref`
* `MyClass::arrayref`
* etc.

Attempting to utilize incompatible data types gives the same behavior
and same errors in both interpreted mode and compiled mode, for
example:

```
#!/usr/bin/perl
use Perl::Types;

sub squared {
{ my number $RETURN_TYPE };
( my number $base ) = @ARG;
return $base ** 2;
}

squared(2); # FINE
squared(2.3); # FINE
squared(to_number('2')); # FINE
my number $foo = 23;
squared($foo); # FINE

squared(); # ERROR ENVxx, TYPE-CHECKING MISMATCH: number value expected but ...
squared('2'); # ERROR ENVxx, TYPE-CHECKING MISMATCH: number value expected but ...
my string $bar = 'howdy';
squared($bar); # ERROR ENVxx, TYPE-CHECKING MISMATCH: number value expected but ...
squared([2]); # ERROR ENVxx, TYPE-CHECKING MISMATCH: number value expected but ...
```

The syntax for arrays and hashes is similarly straightforward:
```
sub multiply_array {
{ my number::arrayref $RETURN_TYPE };
( my integer $input_integer, my number::arrayref $input_array ) = @ARG;
my number::arrayref $output_array = [
$input_integer * $input_array->[0],
$input_integer * $input_array->[1],
$input_integer * $input_array->[2]
];
return $output_array;
}

sub multiply_hash {
{ my number::hashref $RETURN_TYPE };
( my integer $input_integer, my number::hashref $input_hash ) = @ARG;
my number::hashref $output_hash = {
a => $input_integer * $input_hash->{a},
b => $input_integer * $input_hash->{b},
c => $input_integer * $input_hash->{c}
};
return $output_hash;
}
```

## Here are the benefits of this

The primary benefit of including `Perl::Types` in the Perl core
distribution is that it will provide a greatly-needed capability
of exposing the underlying C-level data types and data structures
to every Perl programmer, so they may utilize Perl data types to
achieve a number of benefits including but not limited to:

* increased performance
* code correctness
* type safety (type checking)
* memory safety (bounds checking)
* documentation of code intent
* potential for polymorphism
* potential for derived or synthetic types

Additionally, this foundational support for enabling Perl data
types at the interpreter level will allow for the creation of
synthetic or unnatural data types and data structures to be built
on top of `Perl::Types` itself. For example, the capabilities
provided in `Perl::Types` are necessary for any effort to introduce
real natural type checking constraints related to Perl's new `class`
keyword.

## Here are potential problems

Because the Perl interpreter has already implemented both the real
natural Perl data types, as well as the required `my TYPE $var`
syntax construct, we therefore do not foresee the introduction of
any significant issues by including `Perl::Types` in the Perl core
distribution.

The largest barrier to adoption for the Perl compiler is the need
for numerous non-Perl dependencies, such as the C++ compiler and
other libraries. This barrier will be completely removed for the
`Perl::Types` distribution, due to being refactored out of the
compiler distribution and removal of all non-core dependencies.

On Behalf of the _Perl::Types Committee_,
Brett Estrade

--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
Lot of such discussions were made in Oshun, so few notes:
- will it pollute global symbol space or will it have separated space?
- will it be available at runtime
- please reserve prefix syntax for alternate internal representation (eg:
ordered hashes, sparse arrays, ...)
- be modern - typical stack is SQL (postfix type), Perl, some openapi
(postifx type), some typescript (postfix type) - if you want attract new
programmers, don't burden them with additional habits, they need to focus
on their work
- be different - provide something that others do not (well, SQL does) -
declarative constraints
- how it will fit with classical Perl code bases written without this ?
- how it will improve readability of mixed usage? Is mixed usage even
allowed ?

Generally, what I'm missing is comparison with other popular languages, how
they solve problem
- some typical Perl app communicates with (eg as mentioned SQL + openapi +
typescript)
- some more popular languages: python, ruby, java, kotlin is imho minimum,
Rust, Go nice bonus
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, Aug 16, 2023 at 12:37?AM Oodler 577 via perl5-porters <
perl5-porters@perl.org> wrote:

> # Proposed Perl Changes Elevator Pitch for Perl::Types
>

...


> The data type subsystem of the Perl compiler is currently in the
> process of being extracted and refactored as an independant CPAN
> distribution called `Perl::Types`. This distribution provides new,
> core capabilities and thus should be included in the Perl core
> distribution as a "Dual-Life" module.
>

I'm not sure a PPC is necessary to propose a CPAN module to become dual
life. If the module is developed on CPAN, the only purpose of including it
in core is for it to ship with Perl; Perl core has no say in its design or
development on CPAN. Though I will say that there is not a formal process
for deciding which modules to ship with core currently and that is
something that could use improvement.

-Dan
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
Hi there,

On Wed, 16 Aug 2023, Oodler 577 via perl5-porters wrote:

> # Proposed Perl Changes Elevator Pitch for Perl::Types
>
> This document is the first step in the Proposed Perl Changes process:
>
> https://github.com/Perl/PPCs/blob/main/README.md
> ...

I've just spent an hour trying and to all intents and purposes failing
to read this document.

Am I excluded because <browser>?

--

73,
Ged.
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On 2023-08-16 12:06 a.m., G.W. Haywood via perl5-porters wrote:
> On Wed, 16 Aug 2023, Oodler 577 via perl5-porters wrote:
>> https://github.com/Perl/PPCs/blob/main/README.md
>
> I've just spent an hour trying and to all intents and purposes failing
> to read this document.
>
> Am I excluded because <browser>?

This is a simple documentation file on Github, which is a very widely used and
presumably thoroughly tested site.

I can read the page fine on 3 different web browsers, Safari, Firefox, Chrome,
all fairly new versions.

What browser are you using, and can you try a different one? My top
recommendation is Firefox.

-- Darren Duncan
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
Note: I accidentally sent this to Oodler directly, not CC'ing P5P.

On Wed, Aug 16, 2023 at 7:37?AM Oodler 577 via perl5-porters <
perl5-porters@perl.org> wrote:

>
> Perl lacks sufficient exposure of the already-existing real natural
> Perl data types for use by the programmer. This has lead to false
> claims that the Perl interpreter "has no data types". This has
> also lead to countless programmer-hours spent devising synthetic
> or unnatural type systems that rely entirely on fuzzy data guessing
> via regular expressions, etc.


This looks an awful lot like an end-run around the Oshun discussion which I
had to close because some very simple, but important, questions were not
being answered. When I asked (
https://github.com/orgs/Perl-Oshun/discussions/27#discussioncomment-6581803)
a few questions about Will's "real types" approach, there was no response.
Yves (demerphq) got right to the point with pointing out that Will's
approach is extremely unlikely to work:
https://github.com/orgs/Perl-Oshun/discussions/27#discussioncomment-6680632

I finally closed that discussion after waiting two weeks for answers that
never came. So let me ask them again here, in hopes that *someone* who
knows the answers is willing to share them.

1. Can type failures be downgraded to warnings or disabled entirely?

When you're working with a multi-million line code base, having production
come crashing to a halt because your "integer" recieved 3.14 instead of 3
is going to get types ripped out quickly. Thus, this approach would likely
be of little use for existing systems.

2. Gradual typing?

(this was in my original email) *Your examples show types applied to all
variables. I can't find any that show types being gradually added one at a
time. Is that allowed, or is it all or nothing? If it's the latter, it's
completely useless for existing systems.*

(this is new for this email(: gradual typing might be allowed because I've
found an example in the RPerl documentation. I'm unsure if it applies to
Perl::Types, but I would assume it does. However, that makes question 3
even more important.

3. Do these types play well with others?

Per Yves' response, it's unlikely they will. Thus, the following would be
fatal:

my $var1 = 234;my integer $var2 = 456; # Perl::Typesmy $total
= $var1 + $var2;

Does the above work or not? If it doesn't, you've just locked out the
entire CPAN. If that's the case, can you please provide some
interoperability use cases?

I previously asked them in good faith and waited in vain for a response.
Now I'm asking them in exasperation.

Best,
Ovid

On Wed, Aug 16, 2023 at 7:37?AM Oodler 577 via perl5-porters <
perl5-porters@perl.org> wrote:

> # Proposed Perl Changes Elevator Pitch for Perl::Types
>
> This document is the first step in the Proposed Perl Changes process:
>
> https://github.com/Perl/PPCs/blob/main/README.md
>
> Respectfully submitted by the _Perl::Types Committee_:
> * Will Braswell (WBRASWELL), Co-Founder & Chairman
> * Brett Estrade (OODLER), Co-Founder & 1st Vice Chairman
> * Zakariyya Mughal (ZMUGHAL), Co-Founder & 2nd Vice Chairman
> * John Napiorkowski (JJNAPIORK)
> * Darren Duncan (DUNCAND)
> * Nedzad Hrnjica (NHRNJICA)
> * Rohit Manjrekar (MANJREKAR)
> * Paul Millard (MAGUDAS)
> * Joshua Day (HAX)
> * Tyler Bird (BIRDTY)
> * Robbie Hatley (HATLEYSFT)
> * David Warner (WESTBASE)
> * Daniel Mera (DMERA)
> * Duong Vu (DVU)
> * Rajan Shah (RSHAH)
>
> ## Here is a problem
>
> Perl lacks sufficient exposure of the already-existing real natural
> Perl data types for use by the programmer. This has lead to false
> claims that the Perl interpreter "has no data types". This has
> also lead to countless programmer-hours spent devising synthetic
> or unnatural type systems that rely entirely on fuzzy data guessing
> via regular expressions, etc.
>
> Fortunately, the Perl compiler already provides the capability to
> expose the underlying real native C data types which can be used
> by Perl programmers to incrementally improve performance, eventually
> achieving the full native speed of compiled C code. Among other
> features, the Perl compiler also enables real natural data type
> checking with identical behavior in both dynamic (intrepreted) mode
> and static (compiled) mode.
>
> https://metacpan.org/dist/RPerl
>
> The data type subsystem of the Perl compiler is currently in the
> process of being extracted and refactored as an independant CPAN
> distribution called `Perl::Types`. This distribution provides new,
> core capabilities and thus should be included in the Perl core
> distribution as a "Dual-Life" module.
>
> https://github.com/Dual-Life
>
> ## Here is the syntax that we're proposing
>
> The Perl interpreter already has an unused slot in the grammar for
> this very purpose:
>
> `my TYPE $var;`
>
> The Perl interpreter and the Perl compiler already provide the
> basic data types to be used in the grammar slot above:
>
> * `boolean` (`SV` when `SvIsBOOL(sv)` is true, new in 5.36)
> * `integer` (`IV`)
> * `number` (`NV`)
> * `string` (`PV`)
> * `array` (`AV`) & `arrayref` (`RV(AV)`)
> * `hash` (`HV`) & `hashref` (`RV(HV)`)
> * user-defined classes
>
> Custom data structures are declared with compound or nested data
> types composed from the basic types above, for example:
>
> * `integer::arrayref`
> * `integer::arrayref::arrayref`
> * `integer::arrayref::hashref`
> * `integer::arrayref::arrayref::hashref`
> * `string::arrayref`
> * `MyClass::arrayref`
> * etc.
>
> Attempting to utilize incompatible data types gives the same behavior
> and same errors in both interpreted mode and compiled mode, for
> example:
>
> ```
> #!/usr/bin/perl
> use Perl::Types;
>
> sub squared {
> { my number $RETURN_TYPE };
> ( my number $base ) = @ARG;
> return $base ** 2;
> }
>
> squared(2); # FINE
> squared(2.3); # FINE
> squared(to_number('2')); # FINE
> my number $foo = 23;
> squared($foo); # FINE
>
> squared(); # ERROR ENVxx, TYPE-CHECKING MISMATCH: number value
> expected but ...
> squared('2'); # ERROR ENVxx, TYPE-CHECKING MISMATCH: number value
> expected but ...
> my string $bar = 'howdy';
> squared($bar); # ERROR ENVxx, TYPE-CHECKING MISMATCH: number value
> expected but ...
> squared([2]); # ERROR ENVxx, TYPE-CHECKING MISMATCH: number value
> expected but ...
> ```
>
> The syntax for arrays and hashes is similarly straightforward:
> ```
> sub multiply_array {
> { my number::arrayref $RETURN_TYPE };
> ( my integer $input_integer, my number::arrayref $input_array ) = @ARG;
> my number::arrayref $output_array = [
> $input_integer * $input_array->[0],
> $input_integer * $input_array->[1],
> $input_integer * $input_array->[2]
> ];
> return $output_array;
> }
>
> sub multiply_hash {
> { my number::hashref $RETURN_TYPE };
> ( my integer $input_integer, my number::hashref $input_hash ) = @ARG;
> my number::hashref $output_hash = {
> a => $input_integer * $input_hash->{a},
> b => $input_integer * $input_hash->{b},
> c => $input_integer * $input_hash->{c}
> };
> return $output_hash;
> }
> ```
>
> ## Here are the benefits of this
>
> The primary benefit of including `Perl::Types` in the Perl core
> distribution is that it will provide a greatly-needed capability
> of exposing the underlying C-level data types and data structures
> to every Perl programmer, so they may utilize Perl data types to
> achieve a number of benefits including but not limited to:
>
> * increased performance
> * code correctness
> * type safety (type checking)
> * memory safety (bounds checking)
> * documentation of code intent
> * potential for polymorphism
> * potential for derived or synthetic types
>
> Additionally, this foundational support for enabling Perl data
> types at the interpreter level will allow for the creation of
> synthetic or unnatural data types and data structures to be built
> on top of `Perl::Types` itself. For example, the capabilities
> provided in `Perl::Types` are necessary for any effort to introduce
> real natural type checking constraints related to Perl's new `class`
> keyword.
>
> ## Here are potential problems
>
> Because the Perl interpreter has already implemented both the real
> natural Perl data types, as well as the required `my TYPE $var`
> syntax construct, we therefore do not foresee the introduction of
> any significant issues by including `Perl::Types` in the Perl core
> distribution.
>
> The largest barrier to adoption for the Perl compiler is the need
> for numerous non-Perl dependencies, such as the C++ compiler and
> other libraries. This barrier will be completely removed for the
> `Perl::Types` distribution, due to being refactored out of the
> compiler distribution and removal of all non-core dependencies.
>
> On Behalf of the _Perl::Types Committee_,
> Brett Estrade
>
> --
> oodler@cpan.org
> oodler577@sdf-eu.org
> SDF-EU Public Access UNIX System - http://sdfeu.org
> irc.perl.org #openmp #pdl #native
>


--
Curtis "Ovid" Poe
--
CTO, All Around the World
World-class software development and consulting
https://allaroundtheworld.fr/
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, Aug 16, 2023 at 6:37?AM Oodler 577 via perl5-porters <
perl5-porters@perl.org> wrote:

> # Proposed Perl Changes Elevator Pitch for Perl::Types
>
> This document is the first step in the Proposed Perl Changes process:
>
> https://github.com/Perl/PPCs/blob/main/README.md
>
> Respectfully submitted by the _Perl::Types Committee_:
> * Will Braswell (WBRASWELL), Co-Founder & Chairman
> * Brett Estrade (OODLER), Co-Founder & 1st Vice Chairman
> * Zakariyya Mughal (ZMUGHAL), Co-Founder & 2nd Vice Chairman
> * John Napiorkowski (JJNAPIORK)
> * Darren Duncan (DUNCAND)
> * Nedzad Hrnjica (NHRNJICA)
> * Rohit Manjrekar (MANJREKAR)
> * Paul Millard (MAGUDAS)
> * Joshua Day (HAX)
> * Tyler Bird (BIRDTY)
> * Robbie Hatley (HATLEYSFT)
> * David Warner (WESTBASE)
> * Daniel Mera (DMERA)
> * Duong Vu (DVU)
> * Rajan Shah (RSHAH)
>
> ## Here is a problem
>
> Perl lacks sufficient exposure of the already-existing real natural
> Perl data types for use by the programmer. This has lead to false
> claims that the Perl interpreter "has no data types". This has
> also lead to countless programmer-hours spent devising synthetic
> or unnatural type systems that rely entirely on fuzzy data guessing
> via regular expressions, etc.
>
> Fortunately, the Perl compiler already provides the capability to
> expose the underlying real native C data types which can be used
> by Perl programmers to incrementally improve performance, eventually
> achieving the full native speed of compiled C code. Among other
> features, the Perl compiler also enables real natural data type
> checking with identical behavior in both dynamic (intrepreted) mode
> and static (compiled) mode.
>
> https://metacpan.org/dist/RPerl
>
> The data type subsystem of the Perl compiler is currently in the
> process of being extracted and refactored as an independant CPAN
> distribution called `Perl::Types`. This distribution provides new,
> core capabilities and thus should be included in the Perl core
> distribution as a "Dual-Life" module.
>
> https://github.com/Dual-Life
>
> ## Here is the syntax that we're proposing
>
> The Perl interpreter already has an unused slot in the grammar for
> this very purpose:
>
> `my TYPE $var;`
>
> The Perl interpreter and the Perl compiler already provide the
> basic data types to be used in the grammar slot above:
>
> * `boolean` (`SV` when `SvIsBOOL(sv)` is true, new in 5.36)
> * `integer` (`IV`)
> * `number` (`NV`)
> * `string` (`PV`)
> * `array` (`AV`) & `arrayref` (`RV(AV)`)
> * `hash` (`HV`) & `hashref` (`RV(HV)`)
> * user-defined classes
>
> Custom data structures are declared with compound or nested data
> types composed from the basic types above, for example:
>
> * `integer::arrayref`
> * `integer::arrayref::arrayref`
> * `integer::arrayref::hashref`
> * `integer::arrayref::arrayref::hashref`
> * `string::arrayref`
> * `MyClass::arrayref`
> * etc.
>
> Attempting to utilize incompatible data types gives the same behavior
> and same errors in both interpreted mode and compiled mode, for
> example:
>

Frankly, this is all unworkable.

Perl has a very simple type system[1]. Imagining non-existent types to
exist isn't helpful. You may be able to create a system of checks on
assignment/passing, but that's a different thing entirely from those values
having these types. Given that anything can have references, those checks
can't truly provide invariants.

This is not a type system.

Leon

1: https://twitter.com/leon_timmermans/status/1659557093110587394
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, 16 Aug 2023 06:37:07 +0200, Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:

> # Proposed Perl Changes Elevator Pitch for Perl::Types

Y'all should mention that you already threw a non-functional dist onto CPAN,

https://metacpan.org/dist/Perl-Types

for which i sent feedback noting PAUSE permission issues, which you did not address then or now

https://gitlab.com/scienceperl/perl-types/-/issues/1

--
With regards,
Christian Walde
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On 8/16/23 03:06, G.W. Haywood via perl5-porters wrote:
> Hi there,
>
> On Wed, 16 Aug 2023, Oodler 577 via perl5-porters wrote:
>
>> # Proposed Perl Changes Elevator Pitch for Perl::Types
>>
>> This document is the first step in the Proposed Perl Changes process:
>>
>> https://github.com/Perl/PPCs/blob/main/README.md
>> ...
>
> I've just spent an hour trying and to all intents and purposes failing
> to read this document.
>
> Am I excluded because <browser>?
>
Try this

https://raw.githubusercontent.com/Perl/PPCs/main/README.md
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, 16 Aug 2023 09:19:37 +0200, Ovid <curtis.poe@gmail.com> wrote:

> 1. Can type failures be downgraded to warnings or disabled entirely? When you're working with a multi-million line >code base, having production come crashing to a halt because your "integer" recieved 3.14 instead of 3 is going to >get types ripped out quickly. Thus, this approach would likely be of little use for existing systems.

while i have other issues with the OP proposal (such as them uploading a broken dist to cpan and grabbing toplevel perms without discussion) i have to ask about this question

if i declare a moo/se attr as isa => Int, and send in 3.14, moo/se will also die

to my knowledge the only way around that is eval, so why would downgrades be needed, rather than proper testing and error catching? or is there a way to downgrade the type errors in moo/se?

--
With regards,
Christian Walde
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
Darren Duncan <darren@darrenduncan.net> wrote:
> On 2023-08-16 12:06 a.m., G.W. Haywood via perl5-porters wrote:
>>
>> Am I excluded because <browser>?
>
> This is a simple documentation file on Github, which is a very widely used and presumably thoroughly tested site.

Hot take: Can't be that well tested if it fails to work without JavaScript.


> What browser are you using, and can you try a different one?

`git clone https://github.com/Perl/PPCs` allows access without a browser, if necessary.


--
Arne Johannessen
<https://arne.johannessen.de/>
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
Hi there,

On Wed, 16 Aug 2023, Diab Jerius wrote:
> On 8/16/23 03:06, G.W. Haywood via perl5-porters wrote:
>> On Wed, 16 Aug 2023, Oodler 577 via perl5-porters wrote:
>>
>>> https://github.com/Perl/PPCs/blob/main/README.md
>>> ...
>> I've just spent an hour trying and to all intents and purposes failing
>> to read this document.
>>
>> Am I excluded because <browser>?
>
> Try this
>
> https://raw.githubusercontent.com/Perl/PPCs/main/README.md

Thank you.

That's legible, but most links to other documents appear as relative
to some unknown root and are thus inaccessible:

* [motivation.md](docs/motivation.md) - why do we want to do something
* [process.md](docs/process.md) - the initial version of the process
* [template.md](docs/template.md) - the PPC template
* [future.md](docs/future.md) - how we see the process evolving
* [others.md](docs/others.md) - what others do (or did), and what we can learn from them

--

73,
Ged.
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
Hi there,

On Wed, 16 Aug 2023, Darren Duncan wrote:
> On 2023-08-16 12:06 a.m., G.W. Haywood via perl5-porters wrote:
>> On Wed, 16 Aug 2023, Oodler 577 via perl5-porters wrote:
>>> https://github.com/Perl/PPCs/blob/main/README.md
>>
>> I've just spent an hour trying and to all intents and purposes failing
>> to read this document.
>>
>> Am I excluded because <browser>?
>
> This is a simple documentation file on Github, which is a very widely used
> and presumably thoroughly tested site.

Thanks very much for your reply.

Your presumption is, I think, unjustified. I believe there was a time
when github told me my browser wasn't supported, but it doesn't say
that now. It seems sometimes things render, and sometimes they don't.
The most common problem is not this current README.md issue, but the
fact that much of the embellishment renders in Palemoon as a rotating
icon, which apparently performs no function but prevents all further
interaction with this hapless user.

> I can read the page fine on 3 different web browsers, Safari, Firefox,
> Chrome, all fairly new versions.
>
> What browser are you using,

I'm using Palemoon. The only browser addon installed is uBlock Origin
which is disabled for github.

> and can you try a different one? My top recommendation is Firefox.

I switched to Palemoon very reluctantly after using Firefox for more
than a decade when Firefox became unworkable for me. On Palemoon I'm
currently running six windows with between them about 500 open tabs;
for example I have one window more or less devoted to the RFCs with
currently just over a hundred RFCs open in separate tabs. After some
months of experimentation I chose Palemoon because it was the closest
thing to Firefox that I could find which would do what I needed to do.
I'm not in any hurry to go through all that again.

But what if I'd said it was a Braille reader?

Using a different browser isn't a realistic option, and no matter what
browser I started from, if every time somebody suggested that I use a
different browser I actually did that, I think I'd need to be running
every existing browser. My thin desktop client is a Pi4B with 8GBytes
of RAM but even that isn't enough RAM to pander to the 21st century's
bells and whistles mentality. My wife still uses Firefox, but after a
major upgrade recently she's begun to find it unbearably slow and is
currently searching for alternatives.

For three months now we haven't been able to submit a meter reading to
our electricity supplier (Eon) with either Palemoon or Firefox, and my
wife sent the supplier a revised logo, with the 'n' replaced by 'ff'.

The fact that we're even having this conversation is a symptom of an
epic failure in the processes. Remind me why HTML in the first place?

Here at least, the tools are getting in the way so badly that I'm just
going to walk away from it.

--

73,
Ged.
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
In my opinion as a less experienced Perl programmer, I would have to say I
thoroughly approve of the premises behind Oshun. The idea behind
Perl::Types also is appealing to me, and I feel that potentially the two
systems could coexist, and much work has already been done on both. They
have very different use cases and goals. I am just curious whether Perl's
inherent types are broad enough or flexible enough for most people to use
them.

Avery

On Wed, 16 Aug 2023 at 22:16, G.W. Haywood via perl5-porters <
perl5-porters@perl.org> wrote:

> Hi there,
>
> On Wed, 16 Aug 2023, Darren Duncan wrote:
> > On 2023-08-16 12:06 a.m., G.W. Haywood via perl5-porters wrote:
> >> On Wed, 16 Aug 2023, Oodler 577 via perl5-porters wrote:
> >>> https://github.com/Perl/PPCs/blob/main/README.md
> >>
> >> I've just spent an hour trying and to all intents and purposes failing
> >> to read this document.
> >>
> >> Am I excluded because <browser>?
> >
> > This is a simple documentation file on Github, which is a very widely
> used
> > and presumably thoroughly tested site.
>
> Thanks very much for your reply.
>
> Your presumption is, I think, unjustified. I believe there was a time
> when github told me my browser wasn't supported, but it doesn't say
> that now. It seems sometimes things render, and sometimes they don't.
> The most common problem is not this current README.md issue, but the
> fact that much of the embellishment renders in Palemoon as a rotating
> icon, which apparently performs no function but prevents all further
> interaction with this hapless user.
>
> > I can read the page fine on 3 different web browsers, Safari, Firefox,
> > Chrome, all fairly new versions.
> >
> > What browser are you using,
>
> I'm using Palemoon. The only browser addon installed is uBlock Origin
> which is disabled for github.
>
> > and can you try a different one? My top recommendation is Firefox.
>
> I switched to Palemoon very reluctantly after using Firefox for more
> than a decade when Firefox became unworkable for me. On Palemoon I'm
> currently running six windows with between them about 500 open tabs;
> for example I have one window more or less devoted to the RFCs with
> currently just over a hundred RFCs open in separate tabs. After some
> months of experimentation I chose Palemoon because it was the closest
> thing to Firefox that I could find which would do what I needed to do.
> I'm not in any hurry to go through all that again.
>
> But what if I'd said it was a Braille reader?
>
> Using a different browser isn't a realistic option, and no matter what
> browser I started from, if every time somebody suggested that I use a
> different browser I actually did that, I think I'd need to be running
> every existing browser. My thin desktop client is a Pi4B with 8GBytes
> of RAM but even that isn't enough RAM to pander to the 21st century's
> bells and whistles mentality. My wife still uses Firefox, but after a
> major upgrade recently she's begun to find it unbearably slow and is
> currently searching for alternatives.
>
> For three months now we haven't been able to submit a meter reading to
> our electricity supplier (Eon) with either Palemoon or Firefox, and my
> wife sent the supplier a revised logo, with the 'n' replaced by 'ff'.
>
> The fact that we're even having this conversation is a symptom of an
> epic failure in the processes. Remind me why HTML in the first place?
>
> Here at least, the tools are getting in the way so badly that I'm just
> going to walk away from it.
>
> --
>
> 73,
> Ged.
>
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, 16 Aug 2023 09:20:08 +0200, Leon Timmermans <fawaka@gmail.com> wrote:

> On Wed, Aug 16, 2023 at 6:37?AM Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:
>> # Proposed Perl Changes Elevator Pitch for Perl::Types
>
> Frankly, this is all unworkable.
>
> Perl has a very simple type system[1]. Imagining non-existent types to exist isn't helpful. You may be able to create >a system of checks on assignment/passing, but that's a different thing entirely from those values having these >types. Given that anything can have references, those checks can't truly provide invariants.
>
> This is not a type system.
>
> Leon
>
> 1: https://twitter.com/leon_timmermans/status/1659557093110587394

Highly agreed.

I think it's a very important distinction that perl already HAS a type system, and that what some people think is a type system is indeed just runtime checks; and that modifying the existing type system is very hard, and building anything outside it would not be a type system at all, and if you want checks, think of them as checks.

--
With regards,
Christian Walde
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
Op 16-08-2023 om 11:57 schreef G.W. Haywood via perl5-porters:
> Thank you.
>
> That's legible, but most links to other documents appear as relative
> to some unknown root and are thus inaccessible:
>
> * [motivation.md](docs/motivation.md) - why do we want to do something
> * [process.md](docs/process.md) - the initial version of the process
> * [template.md](docs/template.md) - the PPC template
> * [future.md](docs/future.md) - how we see the process evolving
> * [others.md](docs/others.md) - what others do (or did), and what we
> can learn from them


The root obviously being the path to the current document, as with any
relative link.


HTH,

M4
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, Aug 16, 2023 at 2:37?PM Oodler 577 via perl5-porters <
perl5-porters@perl.org> wrote:


> [snip]
> Perl lacks sufficient exposure of the already-existing real natural
> Perl data types for use by the programmer.
>

At the pure-perl level, I probably agree with that assertion.
But XS has always provided me with the information that I need.

Perl::Types installs cleanly for me, and has an impeccable record with
cpan-testers.
My main concern at this stage would be:

> perldoc Perl::Types
No documentation found for "Perl::Types".

There's no way that I am going to look critically at a module that has no
documentation.

Cheers,
Rob
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, Aug 16, 2023 at 5:33?PM sisyphus <sisyphus359@gmail.com> wrote:
>
> Perl::Types installs cleanly for me, and has an impeccable record with cpan-testers.

Easy to do - it doesn't implement anything.
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, Aug 16, 2023 at 04:37:07AM +0000, Oodler 577 via perl5-porters wrote:
> # Proposed Perl Changes Elevator Pitch for Perl::Types
[...]
> Fortunately, the Perl compiler already provides

By "Perl compiler", do you mean RPerl?

> #!/usr/bin/perl
> use Perl::Types;
>
> sub squared {
> { my number $RETURN_TYPE };
> ( my number $base ) = @ARG;
> return $base ** 2;
> }
>

That's weird perl syntax. What's @ARG and $RETURN_TYPE? Is this something
RPerl related?

In what circumstances are these type checks carried out / enforced? Is it
just on scalar and list assignment? Or more generally? For example, does
this croak?

sub mutate { $_[0] = 'foo' }
my number $x;
mutate($x);

Speaking as a perl internals expert, can you explain to me in general
terms how Perl::Types does its thing?


--
Indomitable in retreat, invincible in advance, insufferable in victory
-- Churchill on Montgomery
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
> Re: PPC Elevator Pitch for Perl::Types
> From: Dave Mitchell
> Date: August 18, 2023 09:19
> Subject: Re: PPC Elevator Pitch for Perl::Types
> Message ID: ZN83kPGe3bEaC5O4@iabyn.com

Hi Dave, thank you for your reply. Please see our answer inline,
below.

> On Wed, Aug 16, 2023 at 04:37:07AM +0000, Oodler 577 via perl5-porters wrote:
> > # Proposed Perl Changes Elevator Pitch for Perl::Types
> [...]
> > Fortunately, the Perl compiler already provides

> By "Perl compiler", do you mean RPerl?

Yes.

> > #!/usr/bin/perl
> > use Perl::Types;
> >
> > sub squared {
> > { my number $RETURN_TYPE };
> > ( my number $base ) = @ARG;
> > return $base ** 2;
> > }
> >

> That's weird perl syntax. What's @ARG and $RETURN_TYPE? Is this something
> RPerl related?

`@ARG` is just the alias for `@_`, provided by `English.pm`.

https://perldoc.perl.org/perlvar#@ARG

https://perldoc.perl.org/English

`$RETURN_TYPE` was the simplest pure-Perl syntax we could come up
with, which allows us to specify a subroutine's return type without
changing its behavior. Can you please suggest possible pure-Perl
syntax alternatives for specifying a subroutine return type, without
requiring any changes to the existing Perl internals?

> In what circumstances are these type checks carried out / enforced? Is it
> just on scalar and list assignment? Or more generally? For example, does
> this croak?

> sub mutate { $_[0] = 'foo' }
> my number $x;
> mutate($x);

The Perl compiler currently supports type enforcement for subroutine
calls, so that is our starting point for Perl::Types. Thus, your
example above would not croak, because the subroutine does not
specify any data types for its input arguments. Type checking is
simply disabled for subroutines without input argument types.

If you added `( my number $my_arg ) = @ARG;` to the top of your
`mutate()` subroutine, then yes it would croak with a complaint
`... number value expected but undefined/null value found ...`
because you never assigned a value to `$x`. This is achieved by
inserting calls to the appropriate type-checking C macros or
functions for each typed input argument, inserted immediately
following the `@ARG` statement. So for your `mutate()` subroutine,
Perl::Types would automatically call either the `number_CHECK()`
or `number_CHECKTRACE()` macro on the value received into `$my_arg`,
which is where the croaking occurs:

https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/DataType/Number.h#L137-149

```c
// [[[ TYPE-CHECKING MACROS ]]]
#define number_CHECK(possible_number) \
(not(SvOK(possible_number)) ? \
croak("\nERROR ENV00, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but undefined/null value found,\ncroaking") : \
(not(SvNOKp(possible_number) || SvIOKp(possible_number)) ? \
croak("\nERROR ENV01, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but non-number value found,\ncroaking") : \
(void)0))
#define number_CHECKTRACE(possible_number, variable_name, subroutine_name) \
(not(SvOK(possible_number)) ? \
croak("\nERROR ENV00, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but undefined/null value found,\nin variable %s from subroutine %s,\ncroaking", variable_name, subroutine_name) : \
(not(SvNOKp(possible_number) || SvIOKp(possible_number)) ? \
croak("\nERROR ENV01, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but non-number value found,\nin variable %s from subroutine %s,\ncroaking", variable_name, subroutine_name) : \
(void)0))
```

> Speaking as a perl internals expert, can you explain to me in general
> terms how Perl::Types does its thing?

As you can see in the C macros above, we are exposing the real
native Perl data types by directly accessing the `SvOK()`, `SvIOKp()`,
and `SvNOKp()` internals. Perl::Types is not inventing its own
definition of types, it is only exposing the already-existing real
native Perl data types such as `IV`, `NV`, `PV`, etc. Real native
Perl data structures can likewise be exposed by way of the `AV`
and `HV` Perl data types, by directly accessing `SvAROKp()` and
`SvHROKp()`:

https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/DataStructure/Array/SubTypes1D.cpp#L72-118
https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/DataStructure/Hash/SubTypes1D.cpp#L92-166

```c
boolean number_arrayref_CHECK(SV* possible_number_arrayref, const boolean no_croak)
{
if ( not( SvOK(possible_number_arrayref) ) ) { CROAK_OR_RETURN(no_croak, "\nERROR ENVAVRV00, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber_arrayref value expected but undefined/null value found,\ncroaking") }
if ( not( SvAROKp(possible_number_arrayref) ) ) { CROAK_OR_RETURN(no_croak, "\nERROR ENVAVRV01, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber_arrayref value expected but non-arrayref value found,\ncroaking") }

AV* possible_number_array;
integer possible_number_array_length;
integer i;
SV** possible_number_array_element;

possible_number_array = (AV*)SvRV(possible_number_arrayref);
possible_number_array_length = av_len(possible_number_array) + 1;

for (i = 0; i < possible_number_array_length; ++i) // incrementing iteration
{
possible_number_array_element = av_fetch(possible_number_array, i, 0);

if (not(SvOK(*possible_number_array_element))) { CROAK_OR_RETURN(no_croak, "\nERROR ENVAVRV02, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but undefined/null value found at index %"INTEGER",\ncroaking", i) }
if (not(SvNOKp(*possible_number_array_element) || SvIOKp(*possible_number_array_element))) { CROAK_OR_RETURN(no_croak, "\nERROR ENVAVRV03, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but non-number value found at index %"INTEGER",\ncroaking", i) }
}

return 1;
}
```

(Please see the links above for `number_arrayref_CHECKTRACE()`,
etc.)

Type checking is currently controlled on a per-file basis using
the `TYPE_CHECKING` preprocessor directive:

https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/Test/TypeCheckingTrace/AllTypes.pm#L1-2

```perl
# [[[ PREPROCESSOR ]]]
# <<< TYPE_CHECKING: TRACE >>>
```

The `TYPE_CHECKING` directive can have a value of `OFF` for disabled,
`ON` to call the `foo_CHECK()` macros/functions, and `TRACE` to
call the `foo_CHECKTRACE()` macros/functions. The only difference
between `ON` and `TRACE` is the inclusion of the offending subroutine
and variable names for easier debugging.

Does that help answer your initial questions?

> --
> Indomitable in retreat, invincible in advance, insufferable in victory
> -- Churchill on Montgomery

On Behalf of the _Perl::Types Committee_,
Brett Estrade

--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Sat, 19 Aug 2023 04:56:13 +0200, Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:

> On Behalf of the _Perl::Types Committee_,

You're speaking for 15 people here. Do any of you plan at any point to address the fact that when you actually factor out your planned boolean.pm and string.pm and upload it, PAUSE will just mark your upload as unauthorized because you ain't got the perms? Or the smash and grab y'all did on a bunch of top level names?

https://pause.perl.org/pause/authenquery?ACTION=peek_perms&pause99_peek_perms_by=a&pause99_peek_perms_query=wbraswell&pause99_peek_perms_sub=Submit

--
With regards,
Christian Walde
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Sat, Aug 19, 2023 at 02:56:13AM +0000, Oodler 577 via perl5-porters wrote:
> Does that help answer your initial questions?

'fraid not :-)

If I am understanding correctly, Perl::Types is intended to be something
which can be used stand-alone, independent of RPerl, and which you want to
be bundled with the perl core.

Within that context, how does adding 'use Perl::Types' at the top of a
perl (not RPerl) program do its thing? What mechanism are you using that
causes this line in a non-RPerl program to croak;

my number $x;
...
$x = 'foo'; # croak

e.g. is it a source filter, set magic attached to $x, or ...?

Also, from your reply about my mutator example not croaking by default,
this seems to imply that it's quite possible for $x to obtain a
non-numeric value under some circumstances. So, by default, what
circumstances will croak and which will silently allow $x to become
something other than a number? E.g. which of these lines croaks?

$x = 'foo';
$x =~ s/1/a/;
substr($x,0,1) = 'foo';
my $y = substr($x,0,1);

Just in general terms I'm still confused as to what effect adding
'Perl::Types' to my program will have, and how it achieves that effect.



--
A problem shared is a problem doubled.
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Sat, Aug 19, 2023 at 4:56?AM Oodler 577 via perl5-porters <
perl5-porters@perl.org> wrote:

> > In what circumstances are these type checks carried out / enforced? Is it
> > just on scalar and list assignment? Or more generally? For example, does
> > this croak?
>
> > sub mutate { $_[0] = 'foo' }
> > my number $x;
> > mutate($x);
>
> The Perl compiler currently supports type enforcement for subroutine
> calls, so that is our starting point for Perl::Types. Thus, your
> example above would not croak, because the subroutine does not
> specify any data types for its input arguments. Type checking is
> simply disabled for subroutines without input argument types.
>

What was being asked was about the behavior of the @_ array. $_[0] is an
alias to $x. Assigning to $_[0] is the same as assigning to $x. Why does it
suddenly lose its knowledge of its type when its in the sub?


> The `TYPE_CHECKING` directive can have a value of `OFF` for disabled,
> `ON` to call the `foo_CHECK()` macros/functions, and `TRACE` to
> call the `foo_CHECKTRACE()` macros/functions. The only difference
> between `ON` and `TRACE` is the inclusion of the offending subroutine
> and variable names for easier debugging.
>
> Does that help answer your initial questions?
>

That answers one of my questions about being able to disable them. It
doesn't answer my question about whether or not this will work:

my $var1 = 234;my integer $var2 = 456; # Perl::Typesmy $total
= $var1 + $var2;

You haven't answered my questions on github. You haven't answered them in
this thread. You haven't addressed Yves' concerns which were raised on
github, where he clearly explains *why* this proposal is not likely to work
(
https://github.com/orgs/Perl-Apollo/discussions/27#discussioncomment-6680632
).

Why are you not answering those questions?

--
Curtis "Ovid" Poe
--
CTO, All Around the World
World-class software development and consulting
https://allaroundtheworld.fr/
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Sat, Aug 19, 2023 at 4:56?AM Oodler 577 via perl5-porters <
perl5-porters@perl.org> wrote:

> > In what circumstances are these type checks carried out / enforced? Is it
> > just on scalar and list assignment? Or more generally? For example, does
> > this croak?
>
> > sub mutate { $_[0] = 'foo' }
> > my number $x;
> > mutate($x);
>
> The Perl compiler currently supports type enforcement for subroutine
> calls, so that is our starting point for Perl::Types. Thus, your
> example above would not croak, because the subroutine does not
> specify any data types for its input arguments. Type checking is
> simply disabled for subroutines without input argument types.
>
> If you added `( my number $my_arg ) = @ARG;` to the top of your
> `mutate()` subroutine, then yes it would croak with a complaint
> `... number value expected but undefined/null value found ...`
> because you never assigned a value to `$x`. This is achieved by
> inserting calls to the appropriate type-checking C macros or
> functions for each typed input argument, inserted immediately
> following the `@ARG` statement. So for your `mutate()` subroutine,
> Perl::Types would automatically call either the `number_CHECK()`
> or `number_CHECKTRACE()` macro on the value received into `$my_arg`,
> which is where the croaking occurs:
>
>
> https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/DataType/Number.h#L137-149
>
> ```c
> // [[[ TYPE-CHECKING MACROS ]]]
> #define number_CHECK(possible_number) \
> (not(SvOK(possible_number)) ? \
> croak("\nERROR ENV00, TYPE-CHECKING MISMATCH,
> CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but
> undefined/null value found,\ncroaking") : \
> (not(SvNOKp(possible_number) ||
> SvIOKp(possible_number)) ? \
> croak("\nERROR ENV01,
> TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value
> expected but non-number value found,\ncroaking") : \
> (void)0))
> #define number_CHECKTRACE(possible_number, variable_name, subroutine_name)
> \
> (not(SvOK(possible_number)) ? \
> croak("\nERROR ENV00, TYPE-CHECKING MISMATCH,
> CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but
> undefined/null value found,\nin variable %s from subroutine %s,\ncroaking",
> variable_name, subroutine_name) : \
> (not(SvNOKp(possible_number) ||
> SvIOKp(possible_number)) ? \
> croak("\nERROR ENV01,
> TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value
> expected but non-number value found,\nin variable %s from subroutine
> %s,\ncroaking", variable_name, subroutine_name) : \
> (void)0))
> ```
>
> > Speaking as a perl internals expert, can you explain to me in general
> > terms how Perl::Types does its thing?
>
> As you can see in the C macros above, we are exposing the real
> native Perl data types by directly accessing the `SvOK()`, `SvIOKp()`,
> and `SvNOKp()` internals. Perl::Types is not inventing its own
> definition of types, it is only exposing the already-existing real
> native Perl data types such as `IV`, `NV`, `PV`, etc. Real native
> Perl data structures can likewise be exposed by way of the `AV`
> and `HV` Perl data types, by directly accessing `SvAROKp()` and
> `SvHROKp()`:


And all of that is entirely wrong. Scalars have a has-a relationship with
IV/NV/PV/RV (with only two of them being mutually exclusive with each
other), and looking at it the right/wrong way can change three of these.
Your concept of a value being a number or not is entirely fictional.

Leon
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Sat, Aug 19, 2023 at 9:40?AM Dave Mitchell <davem@iabyn.com> wrote:

> On Sat, Aug 19, 2023 at 02:56:13AM +0000, Oodler 577 via perl5-porters
> wrote:
> > Does that help answer your initial questions?
>
> 'fraid not :-)
>
> If I am understanding correctly, Perl::Types is intended to be something
> which can be used stand-alone, independent of RPerl, and which you want to
> be bundled with the perl core.
>
> Within that context, how does adding 'use Perl::Types' at the top of a
> perl (not RPerl) program do its thing? What mechanism are you using that
> causes this line in a non-RPerl program to croak;
>
> my number $x;
> ...
> $x = 'foo'; # croak
>
> e.g. is it a source filter, set magic attached to $x, or ...?
>
> Also, from your reply about my mutator example not croaking by default,
> this seems to imply that it's quite possible for $x to obtain a
> non-numeric value under some circumstances. So, by default, what
> circumstances will croak and which will silently allow $x to become
> something other than a number? E.g. which of these lines croaks?
>
> $x = 'foo';
> $x =~ s/1/a/;
> substr($x,0,1) = 'foo';
> my $y = substr($x,0,1);
>
> Just in general terms I'm still confused as to what effect adding
> 'Perl::Types' to my program will have, and how it achieves that effect.
>

You're assuming that Perl::Types isn't all vaporware and this is a proposal
by people who know what they're doing. It all becomes much clearer when you
let go of those assumptions.

Leon
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, 16 Aug 2023 04:37:07 +0000
Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:

...

The following is my personal response, though it is shaped somewhat
along the direction that seems to agree with the PSC's feelings overall.

My short reaction to this: No.


My medium-sized reaction to this: This doesn't sound like the sort of
thing that is either a) a natural extension to the way that people
currently write Perl code, nor b) an end-goal direction that I would be
happy to see the language go in.

------

What now follows is a much longer essay explaining my reasoning for
saying the-above. It's not necessary to read this simply to get my
answer.


## A Natural Extension

When trying to design new Perl features, I am often inspired by two
other languages whose history I have followed - C and Scheme. There's
some interesting parallels. I'm not referring to technical features of
those languages, but of some interesting points of history. Both
languages are defined by a formal specification, with multiple
different implementations and users all trying to share it. ANSI C and
then C89 were both specifications that wrote down and formalized what
had been existing common practice around compilers and implementations.
The same was true for Scheme specs up to R5RS. After that, both C99 and
R6RS did something weird. They both (independently) went off in a
direction where the language spec itself tried to invent new concepts,
before they were commonly implemented or commonly used by users of
those languages. I think it's fair to say that neither spec was
well-received by either its implementors or its users. Sure both had
some good points, but in both cases the spec was found to have
over-reached, promising things that implementors didn't want to create
and users couldn't imagine they'd want. In time both were quietly
retconned. C11 mostly builds atop C89, offering as "optional" a bunch of
things that C99 offered but nobody liked. Scheme R7RS has now been
split into a "small" and a "large" model that basically builds on top
of R5RS and pretends R6 never happened.

(There's also some interesting parallel here with Perl: going up to 5,
trying to invent new things at 6, then splitting off to its own new
name while 5 continues in the hope of an eventual 7. But I digress ;) )

The point I'm trying to make here is that successful languages almost
always come out of observing what people are *actually* doing or
wanting to do but can't for lack of features, and formalizing those
behaviours into convenient concepts within the language so everyone can
operate on common terms.

Lets take a comparison here to Perl's subroutine signatures. At first,
Perl didn't have such a feature natively, but gave users the building
blocks (via the @_ array) to construct something of that nature
themselves. So eventually lots of people were writing code looking
something like

sub f { my ($x, $y, @z) = @_; ... }

When signatures were added, they didn't really add fundamentally new
abilities; they just tidied up what had been existing practice up til
that point. They allowed people to write code in a shorter, neater,
less noisy fashion, that still behaved *as if* it was written in the
longer form.

sub f ($x, $y = 123, @z) { ... }

sub f {
@_ >= 1 or die "Too few arguments";
my $x = $_[0];
my $y = @_ > 1 ? $_[1] : 123;
my @z = @_[2..$#_];
...
}

Lately we've added the //= and ||= operators to signature syntax as
well to permit people to write in signatures what they'd often write
before as stuff like `my $y = $_[1] // 123;`.

Signatures were added in order to provide a short neat concise way for
the programmer to give a standard notation for various behaviours
around creating lexicals and inspecting @_ that *they were already
doing*. Signatures have become popular and well-used precisely because
they are just a neater way to rewrite existing code.

What does this mean for a "type system"? Again, it would do well to
check what existing behaviours people are actually writing now. Almost
universally, the kinds of code people are trying to clean up and
replace are variations on a theme of "Do I like this value?" when being
passed into subroutines or methods, stored in object fields, stored in
regular lexicals, that kind of thing. In effect, where subroutine
signatures tidied up code of the form such as `my $x = shift @_`, so
too should a value constraint system tidy up code of the form
`ACCEPTABLE($_[0]) or die "Cannot accept this argument"`.

Keep that in mind in the following.

## End-Goal Direction

This brings me on to my second point. Back in 2020, I wrote a blog post
that I turned into a presentation at a conference, "Perl in 2025",
where I imagined what kind of Perl code I might be writing five years
hence. Many of the points explained in that talk have set the direction
for things I have been actively working on since then. One I've not
really looked at until you bring it up here, is that "type system".

In my talk (https://www.youtube.com/watch?v=raSRNIoUYig), somewhere
around the 25m mark, I start classifying what various folks mean out of
"type systems". There's three main categories:

1. Static code checks
I.e. Can the compiler (perl -c) tell me "this program is bad"?

2. Dynamic value assertions
I.e. Does the program abort if I give it the wrong data?

3. Compiler hints
I.e. can the runtime run faster because it knows certain
conditions will be impossible?

These categories aren't mutually exclusive of course. For example, C's
type system is very much a mix of categories 1 and 3. TypeScript adds
a category 1 system to JavaScript, and Python also has some optional
typing stuff that again mostly fits category 1.

Perl is a very dynamic language - most of the things that you can do
would violate any sense of "static safety" that category 1 would
attempt to give. Perl isn't built for "performance above all else"
anyway, and category 3 would cut off many situations where we actually
like that flexibility - e.g. being able to use overloaded objects like
bigint, bigrat, String::Tagged, etc... in place of native values. Sure,
I agree that having to check for overloading makes code like `$x + $y`
run a bit slower than if you didn't have to check that, but being able
to transparently pass bigint or bigrat values into existing code and
operate on values larger than native platform IV or NV without losing
any precision at all is a great feature to have.

For these reasons, I feel that really only category 2 is the sort of
thing that is something we can, or should, add to Perl. This is why I
bring attention to the idea that we want to automate away the kinds of
"die if I don't like this value" code that people are already writing.
That's basically what category 2 already is, just manually written out
by hand. Whatever Perl might add in future should be an automation and
standardization of that existing style of code.

Furthermore, because I feel sufficiently strongly that this style of
dynamic value constraints at runtime is the best approach to be taking,
I have tried hard to avoid the word "type" when writing about or
describing it. I've said repeatedly and I'll say again: the whole
thing is verymuch "do we like the look of this value?". The key words
here are "look" and "value". It's about dynamic values that the program
actually operates on. It's about what they look like, not what their
underlying in-memory bit-pattern representation actually is.


# A Critique of Perl::Types

With these points in mind, we are now more prepared to take a closer
look at what your Perl::Types proposal suggests. Overall it's hard to
see what real behaviour is being added by the proposal as the details
in the email are very short. The CPAN dist has almost no code, no
tests, no documentation, so it's very hard for me to guess. I therefore
can't say with 100% certainty that what you propose doesn't fit what
I'm about to explain, but from an initial read of it I find it doubtful.

Perhaps, as a starting point, someone could outline what *kind* of type
system you imagine here, with particular reference to the three
categories I outline above. To what extent does what you propose fit
into each of categories 1, 2 or 3?

## An over-sensitivity to internal data representation

Your email talks about the difference between IVs, NVs and PVs and
honestly that is a tiny internal detail of representation waaay down in
the weeds. Perl - as a language and a culture - has never really cared
about whether a number is really a number, or a string containing some
digit characters to represent it in decimal form. 10 and "10" are mostly
the same thing. Sure, the bits stored in memory are different, but what
you can do with them is the same.

Many people use this to great advantage. For example, if you write a
commandline script that takes some sort of "count" argument, you're
probably going to parse it out of the text contained in the @ARGV
array. By nature that will have arrived as text, but that's OK - it's
Perl. As long as the value looks like a number, we can use it as a
number. It would be most un-Perlish to say that text in @ARGV has to be
converted into a pure-number form just to accept commandline
processing. That kind of conversion would be more at home in languages
such as Python, which make much stronger distinctions about numbers vs.
strings.

I don't see anywhere in your proposal where you account for this; a way
to specify "This value should be usable as if it was a number". Don't
forget things like bigint and bigrat exist and can be used as numbers.
Also when thinking about strings, objects can have overloading on them
to behave like strings ((not quite as well as we'd like currently in
Perl, but that's the subject of PPC0013)).

What I would like to see is something like this; where we imagine (for
sake of current argument) that "Numerical" is something that exists -
its actual nature still to be determined.

my Numerical $n;

$n = 10; # permitted
$n = "10"; # also permitted
$n = bigint->new("10"); # also permitted

$n = "hello"; # not permitted; throws some kind of
# exception at runtime

and of course we can apply those to fields, subroutine parameters,
etc.. in the hopefully-obvious way:

class Point {
field Numerical $x;
method move(Numerical $dX) { ... }
}

sub add(Numerical $x, Numerical $y) { ... }

In all of these cases, the ability to put a value constraint on a field
or parameter is really just a shortcut to writing some "check or die"
code manually. As I tried to hammer in above - this is just an
automation of the way that people can currently write these.

class Point { field Numerical $x; ... }
class Point { field $x; ADJUST { is_Numerical($x) or die "Bad x" }
... }

sub add(Numerical $x) { ... }
sub add($x) { is_Numerical($x) or die "Bad x"; ... }

Admittedly the one on plain lexicals isn't easy to write currently, but
it's possible via a little bit of Magic. It's something I may have a
hack at at some point soon.

## An under-sensitivity to particular values

The other thing that I feel is hugely missing from Perl::Types is
further constraints of values. Whereas I basically never care if a
numerical value is an IV, NV, PV, or some overloaded object or
whatever, what I do often care about is whether it is within some
numerical range. Perhaps it has to be positive. Or positive-or-zero. Or
maybe between two bounds - perhaps a percentage only goes up to 100, or
a mix ratio only goes up to 1.0.

And of course further constraints apply a lot more than just numbers.
Maybe for a string I'd constrain a certain length, or to match a
certain regexp pattern.. or object references have to be within a
certain subclass, or have some matching value for one of their fields,
or... whatever. Whatever Perl code I could have written in my
"IS_ACCEPTABLE($param) or die ..." expression, I should be able to
express in a value constraint. I don't currently see anything like
that in your proposal. That strikes me as a big missing feature.


# What Would I Suggest Instead?

I don't feel it very useful for me to write half a book's-worth of text
as a reply that basically says "no don't do that", without suggesting
something else more preferable instead. So I'm going to end this reply
with a quick look at something I'd much rather be considering.

The module Types::Standard seems to set a standard interface for
performing "constraint checks", that fulfils much of the behaviour I
describe above. It's well-known, well-used (via the Type::Tiny module),
and used by lots of people in lots of places.

As a general shape of model (i.e. true/false assertions on "do we like
this look of this value?") it seems far more aligned with the general
shape I outline above. I've even got as far as writing a little
Object::Pad field attribute module for using these check objects on
field assignments

https://metacpan.org/pod/Object::Pad::FieldAttr::Checked

class Point {
field $x :Checked(Num);
...
}

At some point I may get around to writing a similar attribute for
regular lexical variables. I was going to allow it to apply equally to
subroutine signatures, only I discovered Perl doesn't support those
yet. Hrm. Perhaps something for us to add in 5.39...

my $x :Checked(Num);

# not yet supported
sub add($x :Checked(Num)) { ... }

It's surely not perfect. For one, the syntax needs improving - these
kinds of constraints should be upfront syntax on the fields themselves:

class Point {
field Num $x;
}

my Num $x;

sub add(Num $x) { ... }

Performance-wise it could also be made a lot better. Currently every
checker is stored as a CV pointer, so performing a constraint check
involves an entire call_sv() operation. Internally that'd need a lot of
fixing before we'd consider it for core.

There's also the question of what really is the nature of something
like "Num" in the examples above. As the code currently stands, those
are regular Perl expressions that yield checker object instances at
compiletime, to be used to invoke a `->check` method at runtime. If we
had a truely native constraint-check syntax we'd most likely want to
define what a "check" really is as something more fundamental and new
than just that. It would likely want to operate purely in the C level
in most common cases, avoiding entirely any need for evaluating Perl
expressions just to check the common standard constraints.

But that's relatively small detail on the grand scheme of things.
Overall it's going in about the right direction, and any improvements
to it wouldn't fundamentally alter this shape; just make it better at
doing what it currently does.

What it does is very extensible to more parts of Perl, of course. Once
you have constraint checks that give you a "yes/no" answer and can use
them for accepting or rejecting values at assignment time into lexicals
or fields, or invocation time on function calls (see above examples),
you start to find you can go further than that.

A set of yes/no checks allows you to define multiple dispatch on
subroutines, for example:

check Triangluar :is(Shape) where { $_->points == 3 };
check Rectangular :is(Shape) where { $_->points == 4 };
check Pentagonal :is(Shape) where { $_->points == 5 };

multi sub draw(Triangular $shape) { ... }
multi sub draw(Rectangular $shape) { ... }
multi sub draw(Pentagonal $shape) { ... }

Or perhaps to take part in match/case syntax

match($shape : is) {
case(Triangular) { say "My shape has 3 sides" }
case(Rectangular) { say "My shape has 4 sides" }
...
}

In other words: Once you come up with a good shape for this kind of
thing, you find it's applicable in a lot more places than just
parameters to functions, or field assignments in objects. It's this
sort of force-multiplier that makes good components of languages - one
idea that can be reüsed in lots of different situations.

If people are going to spend their time making "some kind of type
system", the sort of structure I explained here is much more the kind
of thing I'd like to see people making. It has great potential to reüse
existing components, it easily fits into and improves the kind of code
people are already writing and have written for years. Straight away
people will be able to see where - and why - to use this new system.

Great languages are made like Lego kits: a collection of individual
pieces that are each simple to describe, but can be combined in lots of
flexible combinations. We should aim to make good bricks.

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Sat, 19 Aug 2023 13:33:52 +0200, Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:

> [...]
>
> If people are going to spend their time making "some kind of type
> system", the sort of structure I explained here is much more the kind
> of thing I'd like to see people making. It has great potential to re?se
> existing components, it easily fits into and improves the kind of code
> people are already writing and have written for years. Straight away
> people will be able to see where - and why - to use this new system.
>
> Great languages are made like Lego kits: a collection of individual
> pieces that are each simple to describe, but can be combined in lots of
> flexible combinations. We should aim to make good bricks.

Honestly this email should be in the perl core documentation.

--
With regards,
Christian Walde
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Sat, 19 Aug 2023 15:57:55 +0200
"Christian Walde" <walde.christian@gmail.com> wrote:

> > Great languages are made like Lego kits: a collection of individual
> > pieces that are each simple to describe, but can be combined in
> > lots of flexible combinations. We should aim to make good bricks.
>
> Honestly this email should be in the perl core documentation.

It's my tribute to the beginning of the R5RS spec, which begins:

"Programming languages should be designed not by piling feature on
top of feature, but by removing the weaknesses and restrictions that
make additional features appear necessary."

-- https://docs.racket-lang.org/r5rs/r5rs-std/r5rs-Z-H-3.html

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
Op 16-08-2023 om 09:19 schreef Ovid:
> Yves (demerphq) got right to the point with pointing out that Will's
> approach is extremely unlikely to work:
> https://github.com/orgs/Perl-Oshun/discussions/27#discussioncomment-6680632


I would say this is the main thing that needs addressing first. Until
this is cleared up, I think all other discussion is futile.


To rephrase shortly, Perl duck typing permeates every aspect of the
language, making the proposal unwieldy at best, but probably impossible
as it tries to use SVs in a very different way than they are used now.
But I may miss something obvious, or something very deep. So can anyone
explain why Perl::Types can work at all, and what changes to the
implementation of the language are needed for that?


HTH,

M4
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Mon, Aug 21, 2023 at 2:38?AM Martijn Lievaart via perl5-porters
<perl5-porters@perl.org> wrote:
>[...] But I may miss something obvious, or something very deep. So can anyone explain why Perl::Types can work at all, and what changes to the implementation of the language are needed for that?

For anything like Perl::Types to work in we're going to at a minimum
need to expand type annotation support, especially around subroutine
signatures.

Any Type system is going to want three things:

1) A way to annotate code with the types (e.g. `my Dog $fido`)
2) A way to assert the type (e.g. `my Dog $fido = Cat->new(); # dies
because Cats aren't Dogs `)
3) A way to define new types (e.g. `type Dog { $_ isa Dog }`)

#3 depends on #2 and #1, with Perl::Types you can just create a class
… how that mechanism works outside of RPerl is currently undefined. In
theory #2 is taken care of if all they're doing is exposing the
underlying SV subtypes. In practice people are arguing that's a
nonsensical thing to do, and ultimately there may need to be some work
there (there definitely is for Oshun style checks).

#1 however can't work without better support from Perl guts because
the mechanism that Perl::Types is currently using[1] will, as best
I've seen, only work on scalars (`my Child @children` doesn't trigger)
and will only work with explicit syntax like `(my Dog $fido, my Cat
$kitty) = @_` which is IMO painful enough I'd avoid using it. There is
also no support (yet) for subroutine signatures `sub (Dog $fido, Cat
$kitty, Child @children) { ... }`.[2]

-Chris

[1] Technically the mechanism that Perl::Types is _currently_ using
won't work at all. The fields pragma only kinda sorta does a check and
Perl::Types isn't even using that. The above is based on work I've
seen from others and replicated myself using Lexical::Types, which
exposes underlying XS APIs … but as far as I can tell those APIs only
exist for scalars, and it doesn't change the fact that `my ( Dog
$fido, Cat $boomer) = @_;` and `sub (Dog $fido, Cat $boomer) {...}`
are syntax errors.

[2] You can currently annotate a return type using a subroutine
attribute `sub adopt :returns(Dog) ($id) { ... }`. Implementing #2 on
subroutines is left as a lemma for the reader.
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
Op 21-08-2023 om 11:21 schreef Chris Prather:
> On Mon, Aug 21, 2023 at 2:38?AM Martijn Lievaart via perl5-porters
> <perl5-porters@perl.org> wrote:
>> [...] But I may miss something obvious, or something very deep. So can anyone explain why Perl::Types can work at all, and what changes to the implementation of the language are needed for that?
> For anything like Perl::Types to work in we're going to at a minimum
> need to expand type annotation support, especially around subroutine
> signatures.
>
> Any Type system is going to want three things:
>
> 1) A way to annotate code with the types (e.g. `my Dog $fido`)
> 2) A way to assert the type (e.g. `my Dog $fido = Cat->new(); # dies
> because Cats aren't Dogs `)
> 3) A way to define new types (e.g. `type Dog { $_ isa Dog }`)
>
> #3 depends on #2 and #1, with Perl::Types you can just create a class
> … how that mechanism works outside of RPerl is currently undefined. In
> theory #2 is taken care of if all they're doing is exposing the
> underlying SV subtypes. In practice people are arguing that's a
> nonsensical thing to do, and ultimately there may need to be some work
> there (there definitely is for Oshun style checks).


So basically you are implying #2 can work for classes (for Perl::Types),
because classes use SVs in a certain predictable way. But for anything
else, this will not work as exposing SVs will not do anything useful for
the context we are looking at, correct?


> #1 however can't work without better support from Perl guts because
> the mechanism that Perl::Types is currently using[1] will, as best
> I've seen, only work on scalars (`my Child @children` doesn't trigger)
> and will only work with explicit syntax like `(my Dog $fido, my Cat
> $kitty) = @_` which is IMO painful enough I'd avoid using it. There is
> also no support (yet) for subroutine signatures `sub (Dog $fido, Cat
> $kitty, Child @children) { ... }`.[2]


That more or less sounds like it is doable, so no big problems there
(although performance impact remains to be seen, obviously).


M4


> [2] You can currently annotate a return type using a subroutine
> attribute `sub adopt :returns(Dog) ($id) { ... }`. Implementing #2 on
> subroutines is left as a lemma for the reader.


:P
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
> On Aug 21, 2023, at 6:30 AM, Martijn Lievaart via perl5-porters <perl5-porters@perl.org> wrote:
> So basically you are implying #2 can work for classes (for Perl::Types), because classes use SVs in a certain predictable way. But for anything else, this will not work as exposing SVs will not do anything useful for the context we are looking at, correct?

Classes are a red-herring here, and kinda orthogonal. Specifically the APIs that things like Lexical::Types exposes simply don’t exist (as far as I could tell) for anything but scalars. It feels like we implemented just enough to make fields.pm work as a proof of concept and then moved on with our lives.

The reason that Perl::Types shouldn’t have any issue after this is that presumably once they know what type a variable is they can simply call SvIOK, SvNOK, or SvPOK …

Looking at RPerl, each type has a class associated with it so I would assume that there is some mechanism XS to perform the assertion that doesn’t use something like Variable::Magic.

I mean if you can solve the annotation problem, worst case scenario is that you implement a system like https://metacpan.org/pod/Object::Pad::FieldAttr::Checked to do the assertion on set and use the various Sv*OKs.

-Chris
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
> From: Dave Mitchell
> Date: August 19, 2023 07:40
> Subject: Re: PPC Elevator Pitch for Perl::Types
> Message ID: ZOBx23dmJJLPb3Cg@iabyn.com

> On Sat, Aug 19, 2023 at 02:56:13AM +0000, Oodler 577 via perl5-porters wrote:
> > Does that help answer your initial questions?

> 'fraid not :-)

Sorry, we'll keep trying our best to explain! ;-)

> If I am understanding correctly, Perl::Types is intended to be something
> which can be used stand-alone, independent of RPerl, and which you want to
> be bundled with the perl core.

Yes, that is absolutely correct.

> Within that context, how does adding 'use Perl::Types' at the top of a
> perl (not RPerl) program do its thing? What mechanism are you using that
> causes this line in a non-RPerl program to croak;

> my number $x;
> ...
> $x = 'foo'; # croak

> e.g. is it a source filter, set magic attached to $x, or ...?

Yes you are correct, the current mechanism for enabling type-checking
for subroutine calls is essentially a type of source filter. As
mentioned in our first reply:

> > The Perl compiler currently supports type enforcement for subroutine calls, so that is our starting point for Perl::Types.

This source-filter-like functionality is currently contained in
the Perl compiler's file `Class.pm` and is triggered by including
`use RPerl;` in a Perl source code file. Similarly, this functionality
will eventually be triggered by the line `use Perl::Types;` instead,
once we complete the refactoring of `Perl::Types` into its own
distribution.

You can see how the `TYPE_CHECKING` preprocessor directive is
handled, with minor differences between the `ON` and `TRACE`
settings:

https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/CompileUnit/Module/Class.pm#L673-715

```perl
if ( $CHECK eq 'ON' ) {
my $i = 0; # integer
foreach my $subroutine_argument ( @{$subroutine_arguments} ) {
# only enable type-checking for arguments of supported type;
# NEED UPGRADE: enable checking of user-defined Class types & all other remaining RPerl types
if (exists $TYPES_SUPPORTED->{$subroutine_argument->[0]}) {
$subroutine_arguments_check_code .= q{ rperltypes::} . $subroutine_argument->[0] . '_CHECK( $_[' . $i . '] );' . "\n"; # does work, hard-code all automatically-generated type-checking code to 'rperltypes::' namespace
}
$i++;
}

activate_subroutine_args_checking( $package_name, $subroutine_name, $subroutine_type, $subroutine_arguments_check_code, $module_filename_long );
$inside_subroutine = 0;
$subroutine_arguments_line = q{};
}
```

You can see that both `ON` and `TRACE` call `activate_subroutine_args_checking()`,
which is where the type-checking calls are inserted into a new subroutine,
that wraps around the original un-type-checked subroutine:

https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/CompileUnit/Module/Class.pm#L1016-1183

```perl
# re-define subroutine call to include type checking code; new header style
do
{
no strict;

# create unchecked symbol table entry for original subroutine
*{ $package_name . '::__UNCHECKED_' . $subroutine_name } = \&{ $package_name . '::' . $subroutine_name }; # short form, symbol table direct, not strict

# delete original symtab entry,
undef *{ $package_name . '::' . $subroutine_name };

# re-create new symtab entry pointing to checking code plus unchecked symtab entry
$subroutine_definition_code .=
'*' . $package_name . '::' . $subroutine_name . ' = sub { ' .
$subroutine_definition_diag_code .
($subroutine_arguments_check_code or "\n") .
' return ' . $package_name . '::__UNCHECKED_' . $subroutine_name . '(@ARG);' . "\n" . '};';

# create new checked symtab entries, for use by Exporter
$check_code_subroutine_name = $package_name . '::__CHECK_CODE_' . $subroutine_name;
$subroutine_definition_code .= "\n" . '*' . $package_name . '::__CHECKED_' . $subroutine_name . ' = \&' . $package_name . '::' . $subroutine_name . "\n" . ';';

$subroutine_definition_code .= "\n" . '*' . $check_code_subroutine_name . ' = sub {' . "\n" . ' my $retval ' . q{ =<<'EOF';} . "\n" . $subroutine_arguments_check_code . "\n" . 'EOF' . "\n" . '};' . "\n";
};

eval($subroutine_definition_code) or (RPerl::diag('ERROR ECOPR02, PRE-PROCESSOR: Possible failure to enable type checking for subroutine ' . $package_name . '::' . $subroutine_name . '(),' . "\n" . $EVAL_ERROR . "\n" . 'not croaking'));
if ($EVAL_ERROR) { croak 'ERROR ECOPR03, PRE-PROCESSOR: Failed to enable type checking for subroutine ' . $package_name . '::' . $subroutine_name . '(),' . "\n" . $EVAL_ERROR . "\n" . 'croaking'; }
```

Thus, any call to your example `mutate()` subroutine would actually
end up calling the new wrapper subroutine instead, which would
start off by type-checking the input argument(s) before proceeding
to run the original `mutate()` code. (As mentioned before, this
would require adding `( my number $my_arg ) = @ARG;` to the top of
`mutate()`, so that `activate_subroutine_args_checking()` knows to
insert a call to `number_CHECK()` or `number_CHECKTRACE()`.)

We can enable type-checking for the subroutine return values by
simply extending this same `activate_subroutine_args_checking()`
to include a call to the appropriate `foo_CHECK()` or `foo_CHECKTRACE()`
right before returning back to the original caller.

Regarding your `my number $x; $x = 'foo';` example, this will
require the use of a `tie` or similar mechanism to intercept every
modification of `$x`, inserting a call to `number_CHECK()` or
`number_CHECKTRACE()` as previously described. In the past, we
have always simply allowed the C(++) compiler to provide this
functionality for us; however, this will have to be explicitly
implemented when `Perl::Types` is refactored into its own distribution.
Arbitrarily-nested data structures (arrays and/or hashes) can be
recursively type-checked using the same `tie` approach, intercepting
any modifications to internal elements and calling `foo_CHECK()`
or `foo_CHECKTRACE()` for each change.

> Also, from your reply about my mutator example not croaking by default,
> this seems to imply that it's quite possible for $x to obtain a
> non-numeric value under some circumstances. So, by default, what
> circumstances will croak and which will silently allow $x to become
> something other than a number? E.g. which of these lines croaks?

> $x = 'foo';
> $x =~ s/1/a/;
> substr($x,0,1) = 'foo';
> my $y = substr($x,0,1);

Once the above-mentioned `tie` functionality is implemented, then
all four of the lines above would potentially give an error if
attempting to store a non-`number` value into the `number`-typed
`$x` variable.

> Just in general terms I'm still confused as to what effect adding
> 'Perl::Types' to my program will have, and how it achieves that effect.

If you set `TYPE_CHECKING` to `OFF` and don't use the Perl compiler,
then `use Perl::Types;` will not have any effect other than allowing
you to use the Perl data types (and their associated helper
subroutines), thereby improving the readability of your code.

If you set `TYPE_CHECKING` to `ON` or `TRACE` (default) and don't
use the Perl compiler, then `use Perl::Types;` will utilize the
source filter mechanism for type-checking errors on subroutine
entry and/or exit, and will also utilize the `tie` mechanism for
type-checking errors on variable modification, thereby improving
the correctness of your code.

If you set `TYPE_CHECKING` to `ON` or `TRACE` (default) and do use
the Perl compiler, then `use Perl::Types;` will utilize the C(++)
compiler for type-checking errors on subroutine entry and/or exit,
as well as variable modification, thereby improving the runtime
performance of your code.

So, as mentioned in the original Elevator Pitch, we can "utilize
Perl data types to achieve a number of benefits including but not
limited to":

* increased performance
* code correctness
* type safety (type checking)
* memory safety (bounds checking)
* documentation of code intent
* potential for polymorphism
* potential for derived or synthetic types

Currently, the Perl compiler has well over 4K individual test cases,
a large number of which relate to the Perl data type system. The
exact number of tests which will be moved from the Perl compiler
into `Perl::Types` will be determined when the refactoring process
is complete.

https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/t

https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/Test

Are we making progress toward answering your initial questions?

On Behalf of the _Perl::Types Committee_,
Brett Estrade

--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Tue, Aug 22, 2023 at 04:19:04AM +0000, Oodler 577 via perl5-porters wrote:
> Yes you are correct, the current mechanism for enabling type-checking
> for subroutine calls is essentially a type of source filter. As
> mentioned in our first reply:
>
> > > The Perl compiler currently supports type enforcement for subroutine calls, so that is our starting point for Perl::Types.
>
> This source-filter-like functionality is currently contained in
> the Perl compiler's file `Class.pm`

So just for the avoidance of doubt, is the proposal that Perl::Types,
when running in a perl (rather than RPerl) environment, will use perl's
actual source filter mechanism, or that it will use some other
"essentially a type of source filter" thing?

If the latter, please expand.

If the former, note that we generally regard the perl source filter
mechanism as deeply flawed, and wouldn't recommend its use in production
code. The basic problem comes down to the old mantra that "only perl can
parse Perl". A source filter may correctly parse the source 99.9% of the
time, but on those 0.1% occasions, it will get something wrong. Maybe it
will get the start of a // operator confused with the start of a pattern.
Or maybe it will trip over some complex code embeded into a pattern:
/...(?{ $x = '/'; }) .../. Or whatever. At that point, code will get
injected at the wrong point into the source, and the end user gets a
compile error from code that isn't even in their source, which is
completely mystifying and hard to debug.

Switch.pm used source filters, and it was the cause of an endless stream
of tickets. It was eventually deprecated and removed from core in 5.14.0.

> Regarding your `my number $x; $x = 'foo';` example, this will
> require the use of a `tie` or similar mechanism

Again, this is very vague. Do you actually mean perl's tie / magic
mechanism? If not, what "similar mechanism" are you proposing to use?

The problem with using actual ties, is that they make the variable very
slow, even if the actual tie methods such as FETCH() are XS code. That's
because a lot of code paths in the perl interpreter have optimisations for
non-magic values. For example, look at pp_add() in pp_hot.c in the perl
source. This implements perl's '+' operator. Obviously in general the two
operands can be anything - ints, ,nums, strings, magic values, overloaded
objects etc, and mixtures thereof. But in pp_add(), the first thing it
does it check the flags of the two operands, and says:

If they are both non magical and non ref, and if both are either
simple ints or simple nums, then just add the two values, check they
haven't overflowed, set the return value and return. Otherwise go
through the complex 200-lines-of-code path which handles magic, mixed
types etc.

So if, for example, an integer variable was marked with get magic, it
would become a lot slower when being added. Similar considerations apply
in many places.

Also, once tie magic starts being applied to arrays and hashes, you start
to hit edges cases. It's very had to make a tied aggregate behave *exactly*
like a plain array/hash in all circumstances, even ignoring the slowdown.

> So, as mentioned in the original Elevator Pitch, we can "utilize
> Perl data types to achieve a number of benefits including but not
> limited to":
>
> * increased performance

So how would you get increased performance? I've already pointed out that
magic tends to slow things down, and the cost of calling a check routine
will slow things down even further.

> * memory safety (bounds checking)

Can you give an example of where currently perl isn't memory safe, but
Perl::Types would make it so?

> * potential for polymorphism

Please explain further.

Ok, that was the technical side of things. Now on to the policy side.
20 years or so ago, perl went through a phase of adding lots of 'useful'
modules to the perl core. This was widely seen as a mistake.

First, it made a particular module seem to be officially endorsed.
Hypothetically, "among several XML parser modules, we chosen this one as
the best and the one you should use". When design flaws in XML::Parser
(say) are discovered, and the general recommendation is to use
XML::BetterParser instead, XML::Parser is still sitting in the perl core
getting an unfair endorsement. And removing it from core is hard, because
now lots of people used it, and they're using it because, well, we
endorsed it!

Second, if modules stop being actively maintained by their author(s) for
whatever reason, then suddenly we become responsible for maintaining it.
It's enough work just maintaining the core perl interpreter, without
taking on extra responsibilities.

Third, in these days of package managers etc, it's relatively easy for
people to install the CPAN modules they want. They will also get the
newest and best version by default, rather than using the old buggy version
bundled with perl. So there is less good reason to bundle a package with
perl.

So these days the policy is not to bundle CPAN modules with perl unless
they are necessary, usually because they are needed as part of the tool
chain. There have been very few new modules added to the perl core in the
last 15 years or so that are capable of acting as standalone CPAN
distributions instead.

So the short answer is that even if Perl::Types really appealed to us, it
is very unlikely that we would agree to bundle it. And I think we're
far from a consensus yet that it appeals.

On a purely individual note, I am finding Perl::Types very unappealing so
far.

--
I took leave and went to hear Mrs Turner's daughter play on the harpsicon,
but Lord, it was enough to make any man sick to hear her; yet I was forced
to commend her highly.
-- The Diary of Samuel Pepys, 1 May 1663
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Tue, Aug 22, 2023 at 12:03?PM Dave Mitchell <davem@iabyn.com> wrote:

> > Regarding your `my number $x; $x = 'foo';` example, this will
> > require the use of a `tie` or similar mechanism



> > * increased performance
>
> So how would you get increased performance? I've already pointed out that
> magic tends to slow things down, and the cost of calling a check routine
> will slow things down even further.
>

For some context: RPerl is a transpiler which converts a limited subset of
Perl-like syntax to C++ <https://news.ycombinator.com/item?id=18306458> and
then runs it at native speed.
integers and floats are "unboxed" and the native C++ code can run at
lightning fast speed.

Perl wasn't designed with software performance in mind and this often has
not been an issue. Much of our program overhead is I/O, network latency,
etc. When we get CPU-bound, however, we struggle. Perl's optimized well for
all sorts of crazy string manipulation and that was *perfect* for the early
web. In today's data-heavy world, along with AI, lots of math is needed and
Perl's not very fast at that.

It really is a problem with Perl and Perl adoption and I don't know how it
can easily solved.

But Perl was designed for *developer* efficiency and the Oshun data check
project leans into that, hard.

As a developer, I want to know that I can write this (hypothetical syntax,
but very similar to our actual code):

# 1. Passing in something that doesn't match a UUID is fatal.
# 2. Returning anything but an arrayref, or if that arrayref contains
# anything that is not an instance of My::Order, is fatal.
sub get_orders( uuid $uuid ) returns ARRAY[OBJECT[My::Order]] {
# within this scope, setting $uuid to any non-UUID value
# is fatal
my $customer = get_customer($uuid);
return $customer->orders;
}

We do not make promises of code performance. We make promises of developer
performance and data correctness. The amount of code you would have to
write to manually verify all of these assumptions is ridiculous, so many
developers skip that entirely.

We offer:

1. Working code (albeit alpha and NOT appropriate for production use)
2. Almost 200,000 passing tests
3. Documentation (though limited)
4. A full, draft spec which needs to be updated when we agree on syntax
5. We handle bad assignments to the variable well, but assignments deep
inside complex data structures are not handled because of performance. This
is a source of contention.
6. Trivial to downgrade data checks to warnings, or disable them for
performance
7. We have an open process where anyone is allowed to participate. I am
a doorman, not a gatekeepr.

When I say "developer performance" instead of "code performance," consider
the following C function:

#include <stdarg.h>

double get_average_temp(int n, ...)
{
double average = 0.0;
va_list ptr;
va_start(ptr, n);

for (int i = 0; i < n - 1; i++) {
average += va_arg(ptr, double);
}
va_end(ptr);

return average / (n - 1);
}

That takes a variadic list of doubles and computes the "average
temperature" for them. It's written in C, so type checks are done at
compile-time and then thrown out at runtime. Very fast for the computer.

For the developer, if those temperatures are accidentally a mixture of
Celcius and Fahrenheit, there will be no error. There will be no warning.
You might not notice something is wrong. This is not a theoretical
problem. This
is a $125 million problem
<https://www.wired.com/2010/11/1110mars-climate-observer-report/>.
(billions, maybe trilions, if you could count all the times this mistake
has been made).

So Oshun assumes we want correct code *first*. (The following assumes
celsius is a user-defined check):

sub get_average_temp(celsius @temps) returns celsius {
return Celsius->new( temp => sum0(@temps) / @temps );
}

Later, if you want polymorphism via multi subs, we *might* be able to
consider something like:

multi sub get_average_temp(celsius @temps) returns celsius {
return Celsius->new( temp => sum0(@temps) / @temps );
}
multi sub get_average_temp(fahrenheit @temps) returns fahrenheit {
return Fahrenheit->new( temp => sum0(@temps) / @temps );
}

But now we're dispatching on what the arguments mean, not just on primitive
value types without semantic content.

This is *Perl*. If you want CPU performance, you're not going to get it by
attaching a few labels on things. The RPerl transpiler approach literally
*cannot* work here. You can't have unboxed ints and floats flying around
perl's twisty-little maze of macros and even if you did, you lose the
*semantic* meaning of them. There's no such thing as a "4". It's "4 *of
something*" and that's what Oshun does.

I have no idea if the Oshun project will ever get accepted, either. While
the general syntax and intent seems favorable to many (because it fits what
Perl already does), the fact that it would be hard to make it performant
might be its death knell. And when that time comes, I'll point out that
these checks can be disabled for production, but if that's not enough, I
will accept that decision.

--
Curtis "Ovid" Poe
--
CTO, All Around the World
World-class software development and consulting
https://allaroundtheworld.fr/
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
* Dave Mitchell <davem@iabyn.com> [2023-08-22 11:02:53 +0100]:

First, thank you for the reply. I got to your conclusion and understand
your stance. I'd like to still address a few techincal things inline.

> On Tue, Aug 22, 2023 at 04:19:04AM +0000, Oodler 577 via perl5-porters wrote:
> > Yes you are correct, the current mechanism for enabling type-checking
> > for subroutine calls is essentially a type of source filter. As
> > mentioned in our first reply:
> >
> > > > The Perl compiler currently supports type enforcement for subroutine calls, so that is our starting point for Perl::Types.
> >
> > This source-filter-like functionality is currently contained in
> > the Perl compiler's file `Class.pm`
>
> So just for the avoidance of doubt, is the proposal that Perl::Types,
> when running in a perl (rather than RPerl) environment, will use perl's
> actual source filter mechanism, or that it will use some other
> "essentially a type of source filter" thing?

Yes, it uses a source filter to start. Lots of things use source filters,
just like lots of things other parts of Perl. Short of carrying along
patches to core, I am not sure how you would really hook into the process
here.

>
> If the latter, please expand.
>
> If the former, note that we generally regard the perl source filter
> mechanism as deeply flawed, and wouldn't recommend its use in production
> code. The basic problem comes down to the old mantra that "only perl can
> parse Perl". A source filter may correctly parse the source 99.9% of the
> time, but on those 0.1% occasions, it will get something wrong. Maybe it
> will get the start of a // operator confused with the start of a pattern.
> Or maybe it will trip over some complex code embeded into a pattern:
> /...(?{ $x = '/'; }) .../. Or whatever. At that point, code will get
> injected at the wrong point into the source, and the end user gets a
> compile error from code that isn't even in their source, which is
> completely mystifying and hard to debug.
>
> Switch.pm used source filters, and it was the cause of an endless stream
> of tickets. It was eventually deprecated and removed from core in 5.14.0.

Understood.

>
> > Regarding your `my number $x; $x = 'foo';` example, this will
> > require the use of a `tie` or similar mechanism
>
> Again, this is very vague. Do you actually mean perl's tie / magic
> mechanism? If not, what "similar mechanism" are you proposing to use?
>

It was an speculative answer to how we'd do something. It is not currently
possible so we simply do not know.

> The problem with using actual ties, is that they make the variable very
> slow, even if the actual tie methods such as FETCH() are XS code. That's

> because a lot of code paths in the perl interpreter have optimisations for
> non-magic values. For example, look at pp_add() in pp_hot.c in the perl
> source. This implements perl's '+' operator. Obviously in general the two
> operands can be anything - ints, ,nums, strings, magic values, overloaded
> objects etc, and mixtures thereof. But in pp_add(), the first thing it
> does it check the flags of the two operands, and says:
>
> If they are both non magical and non ref, and if both are either
> simple ints or simple nums, then just add the two values, check they
> haven't overflowed, set the return value and return. Otherwise go
> through the complex 200-lines-of-code path which handles magic, mixed
> types etc.
>
> So if, for example, an integer variable was marked with get magic, it
> would become a lot slower when being added. Similar considerations apply
> in many places.
>
> Also, once tie magic starts being applied to arrays and hashes, you start
> to hit edges cases. It's very had to make a tied aggregate behave *exactly*
> like a plain array/hash in all circumstances, even ignoring the slowdown.

Again, what recourse do we have? This is the mechanism by which perl gives
us ways to "implement" our own high level data types (SCALAR, HASH, ARRAY).

This is and the source filter being our only options to hook into fundamental
perl "things" is exactly the pain points we as a community need for there
to be some fundamental improvements in. Perhaps through this effort there
will be some motivation to add a more reliable stage that in the past was
only able to be achieved via filters. And with `tie`, it'd be super if there
was a "better" way to Tie there is not. This is a good role for core developers
to fill.

It is the role of the core development to provide proper programming interfaces
for external parties to propose improvements or integrations without dealing
with gobs of very tedious magic; Perl provides these things currently in 3
fundamental ways:

* source filters
* tie interfaces for SCALAR, ARRAY, HASH
* subroutine prototypes (which are IMO great for creating "keywords" UX)

We've asked before, and we will ask again: what mechanism would you suggest;
and if it doesn't exist or isn't mature enough, what changes would be required
to core to more cleanly/appropriately handle what it is we WANT to do here?
Hiring core developers and internal process people is not an option of us,
we're just volunteers like most, with limited time and zero money to throw at
this.

>
> > So, as mentioned in the original Elevator Pitch, we can "utilize
> > Perl data types to achieve a number of benefits including but not
> > limited to":
> >
> > * increased performance
>
> So how would you get increased performance? I've already pointed out that
> magic tends to slow things down, and the cost of calling a check routine
> will slow things down even further.

Performance increased for type checking because we're taking advantage of the
native type checking in the underlying C or C++, give the source filters enable
more or less a "source to source" translation in differing degrees. This is
in contrast to, e.g., creating a framework that simply allows one to apply
regular expressions all over the place. On one hand regexps are slow, on the
otherhand, we still submit - what options do we really have?

It is also important to get this out front, performance does matter; any costs
for setting up the types constraints should be able to be amortized over the
lifetime of the running program to justify its use. Just like one can make
a program run arbitrarily fast if it is not "correct", it can also become
unacceptibly slow if there is too much overhead in the set up. It's the same
trade off we all see every day in other programming projects. It's no different
here.

So performance is absolution a critical point to consider - be it the overhead
induced but the constraints or the benefits of using real (as in C or C++) based
types and checking, which is where this step actually belongs.

>
> > * memory safety (bounds checking)
>
> Can you give an example of where currently perl isn't memory safe, but
> Perl::Types would make it so?

Again, this leverages the underlying C or C++ data structures and capabilities
provided by these compilers and runtimes. It's all about passing it to
the right level. In our case, it is the fundamental C or C++ data type capabilities
present in the compiler and in their runtimes.

>
> > * potential for polymorphism
>
> Please explain further.

The same way it's facilitated everywhere, by dispatching on what the programmer
is passing into the function - in this case, based on real types.

>
> Ok, that was the technical side of things. Now on to the policy side.
> 20 years or so ago, perl went through a phase of adding lots of 'useful'
> modules to the perl core. This was widely seen as a mistake.
>
> First, it made a particular module seem to be officially endorsed.
> Hypothetically, "among several XML parser modules, we chosen this one as
> the best and the one you should use". When design flaws in XML::Parser
> (say) are discovered, and the general recommendation is to use
> XML::BetterParser instead, XML::Parser is still sitting in the perl core
> getting an unfair endorsement. And removing it from core is hard, because
> now lots of people used it, and they're using it because, well, we
> endorsed it!

Are you suggesting some prudence be applied in endorsing one thing over another?
What is the process in place for vetting such modules or subsystems? It is
a sticky situation, i.e., vouching for things.

>
> Second, if modules stop being actively maintained by their author(s) for
> whatever reason, then suddenly we become responsible for maintaining it.
> It's enough work just maintaining the core perl interpreter, without
> taking on extra responsibilities.

This is already an issue for a lot of things and for a lot of people, literally
anywhere in tech.

>
> Third, in these days of package managers etc, it's relatively easy for
> people to install the CPAN modules they want. They will also get the
> newest and best version by default, rather than using the old buggy version
> bundled with perl. So there is less good reason to bundle a package with
> perl.

This is a fair point.

>
> So these days the policy is not to bundle CPAN modules with perl unless
> they are necessary, usually because they are needed as part of the tool
> chain. There have been very few new modules added to the perl core in the
> last 15 years or so that are capable of acting as standalone CPAN
> distributions instead.

Fair enough. I'd like to ask, what recourse do we have to hook into the perl
interpreter in the way that we are, if not to use the limited options present
in perl? Criticizing source filters and any mention of tie is not fair because
that's all we have. The alternative is also not feasible or fair. So what
do you suggest we do here?

>
> So the short answer is that even if Perl::Types really appealed to us, it
> is very unlikely that we would agree to bundle it. And I think we're
> far from a consensus yet that it appeals.
>
> On a purely individual note, I am finding Perl::Types very unappealing so
> far.

Fair enough, thank you for your time in replying. What technical avenue would
you take if you were in our situation, knowing as much as you know and having
taken the time to understand what we are doing here? Like I said above, beyond
source filters and tie, perl doesn't give us many options that don't include
paying a core developer (or more) to incrementally work on the support necessary
to get this working "fast" or "reliably". Because at the end of the day, that's
what it is going to take - a way to work on both sides of the process in order
to simultaneously deliver an advanced Perl module that is unincumbered by the
traditional limitations and dirth of options to hook deeply into what magick
is happening inside of the perl interpreter. And keep in mind, your reply here
will not just help us.

Thank you again.

Cheers,
Brett

>
> --
> I took leave and went to hear Mrs Turner's daughter play on the harpsicon,
> but Lord, it was enough to make any man sick to hear her; yet I was forced
> to commend her highly.
> -- The Diary of Samuel Pepys, 1 May 1663

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Tue, Aug 22, 2023 at 9:48?AM Oodler 577 via perl5-porters <
perl5-porters@perl.org> wrote:

> Yes, it uses a source filter to start. Lots of things use source filters,
> just like lots of things other parts of Perl. Short of carrying along
> patches to core, I am not sure how you would really hook into the process
> here.
> ...
> Fair enough. I'd like to ask, what recourse do we have to hook into the
> perl
> interpreter in the way that we are, if not to use the limited options
> present
> in perl? Criticizing source filters and any mention of tie is not fair
> because
> that's all we have. The alternative is also not feasible or fair. So what
> do you suggest we do here?
>

I wonder if you are not aware of the keyword plugging system, available
since 5.14?
It's used extensively by modules like List::Keywords and Object::Pad as
ways to prototype new functionality that could eventually be brought into
core (and indeed some of it has been, e.g. via Corinna).
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
* Ovid <curtis.poe@gmail.com> [2023-08-22 16:10:00 +0200]:

> On Tue, Aug 22, 2023 at 12:03?PM Dave Mitchell <davem@iabyn.com> wrote:
>
> > > Regarding your `my number $x; $x = 'foo';` example, this will
> > > require the use of a `tie` or similar mechanism
>
> > > * increased performance
> >
> > So how would you get increased performance? I've already pointed out that
> > magic tends to slow things down, and the cost of calling a check routine
> > will slow things down even further.

We're going to continuing to do the best we can given we perl gives us only
so much access to internals on a higher level; and the fact that we don't
have "core" developers in our pocket or a monetary budget to speak of. We
our time and our zeal, outside of that we can only deal with the cards perl
gives us. I wish there were better ways to do this, which IMO is exactly
the kind of things any future perl work should entail. Giving us better and
more performant access to empower new and more powerful CPAN modules.

> >
>
> For some context: RPerl is a transpiler which converts a limited subset of
> Perl-like syntax to C++ <https://news.ycombinator.com/item?id=18306458> and
> then runs it at native speed.
> integers and floats are "unboxed" and the native C++ code can run at
> lightning fast speed.

Mostly True. RPerl is a real subset (R = "restricted"), not "Perl-like".
"Perl-like" is something like Qore(.org), which has actual threads
and REAL C++ data types. And really does look like Perl. I encourage
others to check it out, and always have. The only reason I don't use
it is because it's not the One True Interpreter^TM (and never will
be).

Will even has a full book for free, in PDF form on the website,

http://rperl.org/learning/

All for vaporware, tho.

>
> Perl wasn't designed with software performance in mind and this often has
> not been an issue. Much of our program overhead is I/O, network latency,
> etc. When we get CPU-bound, however, we struggle. Perl's optimized well for
> all sorts of crazy string manipulation and that was *perfect* for the early
> web. In today's data-heavy world, along with AI, lots of math is needed and
> Perl's not very fast at that.

I don't think it is fair to say what Perl was or was not designed
for performance; that's just not a reasonable thing to claim for
people who work on computers most of the day/night. But I know it
wasn't designed for exposing OpenMP, and this is a direction I am
leading and has a nice tie-in to Perl::Types.

Will is an absolute expert with the Perl API and I am far from it,
as much as one can be without being in some club (speaking of
gatekeeping).

I do have a lot of experience in both HPC and Perl, and can say
that Perl most definitly is an amazing driver for all kinds of
performance related things - yes, via C bindings, but also for a
lot of pure Perl things, provided you do the yoeman's work of
actually profiling with the excellent Devel::NYTProf toolset.

Perl's API is untapped by most, but that's shame and the real place
of most improvement would to make it easier to expose is in a mid-
level way; and I see Perl::Types in may ways as a good example
of this. There are many such benefits to building up support for
this underserved are (not pure Perl but not Perl API).

The fact PDL exists leads to your point. However, there is a
historical obsession with optimizing perl and perl code. Why does
Devel::NYTProf exist? While we can't say perl (lower "p") is intended
to complete with C in many cases, it is also demonstrably false
that there are constant attempts to optimize it out the ying-yang
for what it does, ruthlessly so. So rutheless that one can't even
ensure a "read only" operation on a SV/AV/HV is thread safe. That's
pretty extreme.

Performance refers to a lot of things. We all want fast and efficient
code, so please just stop trying to convince us that performance
is not an issue. That's simply false, I don't care what blog post
says it is not.

>
> It really is a problem with Perl and Perl adoption and I don't know how it
> can easily solved.
>
> But Perl was designed for *developer* efficiency and the Oshun data check
> project leans into that, hard.

Ironically, what you are doing is extremely similar to Ada's
approach, part of which is called "design by contract". Ada has
full specifications on that and it's done by actual language
designers on US tax payer's dime. It's not bad, just not novel. It
seems a first pass on understanding how to apply Ada's approach in
describing the kinds of constraints you wish to describe would be
well worth the effort - and maybe a few academic papers. Were you
aware that Oshun is heading decidely into a space that has been
well specified by Ada?

The last time I used Ada was in college, and it was for 1 semester.
It is an interesting languge, used even in real time systems like
avionics. So clearly it can be performant, but it also doens't have
the limitations perl does.

Anyway, I suggestion you suggest you call Oshun what it is, "design
by contract", not only would more people understand at what level
it sits; but it would assist in the internal and external designs
by the mountains of existing implementations and specifications.
It might be novel in Perl, but it is not novel.

>
> As a developer, I want to know that I can write this (hypothetical syntax,
> but very similar to our actual code):

DARPA funded a spate of "High Productivity Computing System"
languages in the 2000s, and it came up with some interesting results.
Some of them could apply to Perl, especially Chapel (originally
ZPL, Ada is something that influenced it).


https://www.lanl.gov/conferences/lacss/2008/slides/barrett.pdf
https://en.wikipedia.org/wiki/High_Productivity_Computing_Systems

Again, you should look up "design by contract" and Ada.

..snip

> We do not make promises of code performance. We make promises of developer
> performance and data correctness. The amount of code you would have to
> write to manually verify all of these assumptions is ridiculous, so many
> developers skip that entirely.

Ignoring actual performance unwise. I am not suggesting pre-mature
optimizing the tricky stuff, but the obvious stuff, yes. It also
immediately loses most of your potential users. So what's the point
in hedging AGAINST performance? Makes me think you're not really
serious.

>
> We offer:
>
> 1. Working code (albeit alpha and NOT appropriate for production use)
> 2. Almost 200,000 passing tests
> 3. Documentation (though limited)
> 4. A full, draft spec which needs to be updated when we agree on syntax
> 5. We handle bad assignments to the variable well, but assignments deep
> inside complex data structures are not handled because of performance. This
> is a source of contention.
> 6. Trivial to downgrade data checks to warnings, or disable them for
> performance

How is this not vaporware and somehow RPerl and Perl::Types is
getting sniped on the sidelines for being vapor? This is getting
stupid and we're both looking stupid.

> 7. We have an open process where anyone is allowed to participate. I am
> a doorman, not a gatekeepr.

We more structured, who cares. We have a gatekeeping process and
are formal. We'll build our in cathedral, you build your bazaar.

>
> When I say "developer performance" instead of "code performance," consider
> the following C function:

You keep saying "developer performance". See,

https://en.wikipedia.org/wiki/High_Productivity_Computing_Systems

And start talking about prior art, nothing you are doing is novel.
At least we don't make that claim.

I do think Chapel could really offer some ideas on how to extend
Perl in actual useful ways, but it's unrelated to your DbC efforts
(which btw do not conflict with Perl::Types, a point we've made).
Perhaps you can show where Perl::Types, as we've demonstrated would
conflict with Oshun. I am not suggesting they are directly composable,
but Perl::Types could definitely assist you where otherwise you'd
just be using regular expressions everywhere (behind some sugar,
of course).

>
> #include <stdarg.h>
>
> double get_average_temp(int n, ...)
> {
> double average = 0.0;
> va_list ptr;
> va_start(ptr, n);
>
> for (int i = 0; i < n - 1; i++) {
> average += va_arg(ptr, double);
> }
> va_end(ptr);
>
> return average / (n - 1);
> }
>
> That takes a variadic list of doubles and computes the "average

Because I had no idea and it seems "important",

variadic := it can take a varying number of arguments

> temperature" for them. It's written in C, so type checks are done at
> compile-time and then thrown out at runtime. Very fast for the computer.
>
> For the developer, if those temperatures are accidentally a mixture of
> Celcius and Fahrenheit, there will be no error. There will be no warning.
> You might not notice something is wrong. This is not a theoretical
> problem. This
> is a $125 million problem
> <https://www.wired.com/2010/11/1110mars-climate-observer-report/>.
> (billions, maybe trilions, if you could count all the times this mistake
> has been made).

I have no doubt lives and lots of money hinge on Perl, but I assure
you lives and a lot more dollars do hinge on Ada, as it is in
avionics and other real time control systems. DbC is a good thing,
and I don't believe Perl::Types steps in your wading pool here. It
sits lower, and the whole point of what we are doing is providing
a basis for things like DbC, rather than it being a way to apply
a bunch of regular expressions. If someone wants that, they can
integrate Validate::Tiny quite nicely into their project.

>
> So Oshun assumes we want correct code *first*. (The following assumes
> celsius is a user-defined check):
>
> sub get_average_temp(celsius @temps) returns celsius {
> return Celsius->new( temp => sum0(@temps) / @temps );
> }
>
> Later, if you want polymorphism via multi subs, we *might* be able to
> consider something like:
>
> multi sub get_average_temp(celsius @temps) returns celsius {
> return Celsius->new( temp => sum0(@temps) / @temps );
> }
> multi sub get_average_temp(fahrenheit @temps) returns fahrenheit {
> return Fahrenheit->new( temp => sum0(@temps) / @temps );
> }
>
> But now we're dispatching on what the arguments mean, not just on primitive
> value types without semantic content.
>
> This is *Perl*. If you want CPU performance, you're not going to get it by
> attaching a few labels on things. The RPerl transpiler approach literally
> *cannot* work here. You can't have unboxed ints and floats flying around
> perl's twisty-little maze of macros and even if you did, you lose the
> *semantic* meaning of them. There's no such thing as a "4". It's "4 *of
> something*" and that's what Oshun does.

The "R" in "RPerl" means "restricted". It is for people interested
in the tradeoff between leveraging a real type system (from underlying
C or C++) into their code for performance and type safety. It's
not and never was offered as a design by contract approach. It sits
lower than Oshun, and would benefit your project by giving you
access in a lot of cases to the underlying data structures in the
perl interpreter, both at compile time and at runtime - and varying
degress of abstraction from the high level perl SV/AV/HV to the
actual underlying C or C++ (particular in the case of C++ supported
objects and derived data types).

>
> I have no idea if the Oshun project will ever get accepted, either. While
> the general syntax and intent seems favorable to many (because it fits what
> Perl already does), the fact that it would be hard to make it performant
> might be its death knell. And when that time comes, I'll point out that
> these checks can be disabled for production, but if that's not enough, I
> will accept that decision.
>

It seems that the same barrier of entry exists for Oshun as
Perl::Types. They are different things.

Oshun is "Design by Contract" in Perl. Call it what it is. It'll
help you and anyone interested in it clarify the vision and actually
deliver. You can then focus on the UX of DbC and hedge the performance
but of it to whatever abstraction you're currently sitting atop - be
it regular expressions, something sane like Validate::Tiny, or even
Perl::Types.

Perl::Types provides access to real type systems in perl and below
in the C/C++ compilers. So it sits at a lower level and provides
some compelling access to internal data structures that are otherwise
the realm of witches, "high magic" as it is called.

One thing I will assert is Perl::Types and RPerl is about as much
vaporware as Oshun, so it would be benefit both projects to quit
this "vaporware" BS that your cheerleaders seems to be pushing on
here and on the darker depths of the internet echo chambers. It's not
helpful, and it is clearly not a majority position as evidenced by
the pushback they are receiving.

Cheers,
Brett

> --
> Curtis "Ovid" Poe
> --
> CTO, All Around the World
> World-class software development and consulting
> https://allaroundtheworld.fr/

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
* Karen Etheridge <perl@froods.org> [2023-08-22 10:43:23 -0700]:

> On Tue, Aug 22, 2023 at 9:48?AM Oodler 577 via perl5-porters <
> perl5-porters@perl.org> wrote:
>
> > Yes, it uses a source filter to start. Lots of things use source filters,
> > just like lots of things other parts of Perl. Short of carrying along
> > patches to core, I am not sure how you would really hook into the process
> > here.
> > ...
> > Fair enough. I'd like to ask, what recourse do we have to hook into the
> > perl
> > interpreter in the way that we are, if not to use the limited options
> > present
> > in perl? Criticizing source filters and any mention of tie is not fair
> > because
> > that's all we have. The alternative is also not feasible or fair. So what
> > do you suggest we do here?
> >
>
> I wonder if you are not aware of the keyword plugging system, available
> since 5.14?
> It's used extensively by modules like List::Keywords and Object::Pad as
> ways to prototype new functionality that could eventually be brought into
> core (and indeed some of it has been, e.g. via Corinna).

Thank you, we had not looked at this but will.

Cheers,
Brett

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Tue, 22 Aug 2023 18:45:44 +0000
Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:

> > I wonder if you are not aware of the keyword plugging system,
> > available since 5.14?
> > It's used extensively by modules like List::Keywords and
> > Object::Pad as ways to prototype new functionality that could
> > eventually be brought into core (and indeed some of it has been,
> > e.g. via Corinna).
>
> Thank you, we had not looked at this but will.

It's very powerful; particularly as exposed by XS::Parse::Keyword and
in some cases XS::Parse::Sublike.

With it I've been able to implement:

* async/await syntax
https://metacpan.org/pod/Future::AsyncAwait

* real object syntax
https://metacpan.org/pod/Object::Pad

* real try/catch syntax (that became core's feature 'try')
https://metacpan.org/pod/Syntax::Keyword::Try

* real match/case syntax
https://metacpan.org/pod/Syntax::Keyword::Match

All of these things are in use right now today in various real
systems, real companies actually using this lot for real production
work.

They all play together, because they're not silly "lets rewrite the
source code with a regexp" trickery; they're properly integrated into
the parser in a properly reëntrant way. E.g. observe the way you can
put a match/case inside a try/catch block in an `async method` of a
class. Of particular note I want to draw attention to the fact that
combining `async` from Future::AsyncAwait and `method` from Object::Pad
works just fine despite the fact that neither module knows about the
other. When I wrote about programming languages being like Lego sets,
this is precisely the sort of thing I mean.


In addition at Perl v5.38 we added another mechanism for defining new
infix operators; so now while we're getting rid of smartmatch we can
continue to experiment with better replacements for it.

https://metacpan.org/pod/Syntax::Operator::Equ

https://metacpan.org/pod/Syntax::Operator::Identical

https://metacpan.org/pod/Syntax::Operator::Matches

and again - these all play together just fine. You can use an `equ` or
`=:=` operator inside match/case inside try/catch inside ... I think my
point is clear here.

These are the core-supported mechanisms we've been using for the past
decade to experiment with new syntax and new ideas that we eventually
bring into the core language.

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On 22.08.23 18:48, Oodler 577 via perl5-porters wrote:
> * Dave Mitchell <davem@iabyn.com> [2023-08-22 11:02:53 +0100]:
>
>>> So, as mentioned in the original Elevator Pitch, we can "utilize
>>> Perl data types to achieve a number of benefits including but not
>>> limited to":
>>>
>>> * increased performance
>>
>> So how would you get increased performance? I've already pointed out that
>> magic tends to slow things down, and the cost of calling a check routine
>> will slow things down even further.
>
> Performance increased for type checking

This reply makes no sense. The original claim was increased performance
*of the code*, not increased performance of *checking types*. And the
latter is trivially false: Perl currently does not have a type system,
so it "wastes" zero time on static checks. How can you increase the
performance of that?

> because we're taking advantage of the
> native type checking in the underlying C or C++,

Perl has no underlying C or C++, so how is that going to work? (Also,
C's type system is kind of terrible.)

Besides, pushing type checks into an underlying (or "target") language
is generally a bad idea: It means errors will be reported in terms of
the generated code, not the source syntax written by the programmer.

(Besides besides, C++ is not known for its compilation and type checking
speed.)
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Tue, 22 Aug 2023 20:43:03 +0200, Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:

> vaporware

ovid never used that word.

ovid merely pointed out the basic fact that you have provided no code that
is executable on the official perl distribution

if you have it, please provide



it is also notable that the non-functional code you DO have on CPAN
proposes to provide a string.pm which would violate PAUSE perms, as:

$ cpanm string
--> Working on string
Fetching http://www.cpan.org/authors/id/A/AB/ABERGMAN/types-0.05.tar.gz ... OK

something which you have steadfastly refused reply to in any fashion,
which makes one wonder

--
With regards,
Christian Walde
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Tue, Aug 22, 2023 at 8:43?PM Oodler 577 via perl5-porters <
perl5-porters@perl.org> wrote:

> Mostly True. RPerl is a real subset (R = "restricted"), not "Perl-like".
> "Perl-like" is something like Qore(.org), which has actual threads
> and REAL C++ data types. And really does look like Perl. I encourage
> others to check it out, and always have. The only reason I don't use
> it is because it's not the One True Interpreter^TM (and never will
> be).
>
> Will even has a full book for free, in PDF form on the website,
>
> http://rperl.org/learning/
>
> All for vaporware, tho.
>

No one said rperl is vaporware, I said Perl::Types is. If you don't believe
me, try running «perl -e'use Perl::Types; my integer $foo = "L"'»


> > It really is a problem with Perl and Perl adoption and I don't know how
> it
> > can easily solved.
> >
> > But Perl was designed for *developer* efficiency and the Oshun data check
> > project leans into that, hard.
>
> Ironically, what you are doing is extremely similar to Ada's
> approach, part of which is called "design by contract". Ada has
> full specifications on that and it's done by actual language
> designers on US tax payer's dime. It's not bad, just not novel. It
> seems a first pass on understanding how to apply Ada's approach in
> describing the kinds of constraints you wish to describe would be
> well worth the effort - and maybe a few academic papers. Were you
> aware that Oshun is heading decidely into a space that has been
> well specified by Ada?
>
> The last time I used Ada was in college, and it was for 1 semester.
> It is an interesting languge, used even in real time systems like
> avionics. So clearly it can be performant, but it also doens't have
> the limitations perl does.
>
> Anyway, I suggestion you suggest you call Oshun what it is, "design
> by contract", not only would more people understand at what level
> it sits; but it would assist in the internal and external designs
> by the mountains of existing implementations and specifications.
> It might be novel in Perl, but it is not novel.
>

No, Oshun is not design by contract. Design by contract is fundamentally
about checking code/transitions, not values.

Please stop acting like you're the one here to school people.

> We do not make promises of code performance. We make promises of developer
> > performance and data correctness. The amount of code you would have to
> > write to manually verify all of these assumptions is ridiculous, so many
> > developers skip that entirely.
>
> Ignoring actual performance unwise. I am not suggesting pre-mature
> optimizing the tricky stuff, but the obvious stuff, yes. It also
> immediately loses most of your potential users. So what's the point
> in hedging AGAINST performance? Makes me think you're not really
> serious.
>

Are you?

Leon
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
* Christian Walde <walde.christian@gmail.com> [2023-08-22 23:09:09 +0200]:

> On Tue, 22 Aug 2023 20:43:03 +0200, Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:
>
> > vaporware
>
> ovid never used that word.

I am going to take your word for it, but I believe this statement
is correct in the literal sense.

>
> ovid merely pointed out the basic fact that you have provided no code that
> is executable on the official perl distribution
>
> if you have it, please provide
>
>
>
> it is also notable that the non-functional code you DO have on CPAN
> proposes to provide a string.pm which would violate PAUSE perms, as:
>
> $ cpanm string
> --> Working on string
> Fetching http://www.cpan.org/authors/id/A/AB/ABERGMAN/types-0.05.tar.gz ... OK
>
> something which you have steadfastly refused reply to in any fashion,
> which makes one wonder

Have you inspected the source code of types.pm"?

It is a 21 year old CPAN squatter package that contains the following code:
( direct link, https://metacpan.org/dist/types/source/lib/types.pm):

Note via CPAN, types.pm provides:

* float in lib/types.pm
* int in lib/types.pm
* number in lib/types.pm
* string in lib/types.pm
* unknown in lib/types.pm

And the code, which is unfortunate:

package types;
...
package unknown;
our $dummy = 1;
package int;
our $dummy = 1;
sub check {
return 0 if($_[0] eq 'int' && ($_[1] ne 'number' && $_[1] ne 'int'));
return 1;
}
package float;
use base qw(int);
sub check {
return 0 if($_[1] eq 'string');
return 1;
}
our $dummy = 1;
package number;
use base qw(float);
sub check {
return 0 if($_[1] eq 'string');
return 1;
}
our $dummy = 1;
package string;
use base qw(number);
sub check { return 1};
1;
__END__

And that's just the facts. "Playing nice" with a clear case of CPAN squatting
is hard to do. What do you suggest the path forward is for this pickle?

Cheers,
Brett

>
> --
> With regards,
> Christian Walde

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, 23 Aug 2023 00:02:18 +0200, Oodler 577 <oodler577@sdf-eu.org> wrote:

> * Christian Walde <walde.christian@gmail.com> [2023-08-22 23:09:09 +0200]:
>
>> On Tue, 22 Aug 2023 20:43:03 +0200, Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:
>>
>> > vaporware
>>
>> ovid never used that word.
>
> I am going to take your word for it

i believe it is important to only make accusations one has evidence for

>> ovid merely pointed out the basic fact that you have provided no code that
>> is executable on the official perl distribution
>>
>> if you have it, please provide
>>
>>
>>
>> it is also notable that the non-functional code you DO have on CPAN
>> proposes to provide a string.pm which would violate PAUSE perms, as:
>>
>> $ cpanm string
>> --> Working on string
>> Fetching http://www.cpan.org/authors/id/A/AB/ABERGMAN/types-0.05.tar.gz ... OK
>>
>> something which you have steadfastly refused reply to in any fashion,
>> which makes one wonder
>
> Have you inspected the source code of types.pm"?
>
> It is a 21 year old CPAN squatter package that contains the following code:
> ( direct link, https://metacpan.org/dist/types/source/lib/types.pm):
>
> Note via CPAN, types.pm provides:
>
> * float in lib/types.pm
> * int in lib/types.pm
> * number in lib/types.pm
> * string in lib/types.pm
> * unknown in lib/types.pm
>
> And the code, which is unfortunate:
>
> package types;
> ...
> package unknown;
> our $dummy = 1;
> package int;
> our $dummy = 1;
> sub check {
> return 0 if($_[0] eq 'int' && ($_[1] ne 'number' && $_[1] ne 'int'));
> return 1;
> }
> package float;
> use base qw(int);
> sub check {
> return 0 if($_[1] eq 'string');
> return 1;
> }
> our $dummy = 1;
> package number;
> use base qw(float);
> sub check {
> return 0 if($_[1] eq 'string');
> return 1;
> }
> our $dummy = 1;
> package string;
> use base qw(number);
> sub check { return 1};
> 1;
> __END__
>
> And that's just the facts. "Playing nice" with a clear case of CPAN squatting
> is hard to do. What do you suggest the path forward is for this pickle?

my time is too limited currently to work out suggestions on fixes and i know people already provided suggestions to you which would improve the proposal overall and also address this issue

i am here to provide questions and feedback

that said: is there a known pause policy regarding your identified behavior of squatting?

--
With regards,
Christian Walde
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, Aug 23, 2023 at 12:22?AM Christian Walde <walde.christian@gmail.com>
wrote:

> that said: is there a known pause policy regarding your identified
> behavior of squatting?
>

«Perl reserves all lowercase namespaces for pragmas. That doesn't mean you
can't write a pragma, but you should get the blessing of p5p (
perl5-porters@perl.org).» [1]

So there is a contingency policy for namespaces like these, though I don't
think we've ever used it.

Leon

1:
https://pause.perl.org/pause/query?ACTION=pause_namingmodules#All_lowercase_name
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
* Leon Timmermans <fawaka@gmail.com> [2023-08-22 23:55:09 +0200]:

> On Tue, Aug 22, 2023 at 8:43?PM Oodler 577 via perl5-porters <
> perl5-porters@perl.org> wrote:
>
> > Mostly True. RPerl is a real subset (R = "restricted"), not "Perl-like".
> > "Perl-like" is something like Qore(.org), which has actual threads
> > and REAL C++ data types. And really does look like Perl. I encourage
> > others to check it out, and always have. The only reason I don't use
> > it is because it's not the One True Interpreter^TM (and never will
> > be).
> >
> > Will even has a full book for free, in PDF form on the website,
> >
> > http://rperl.org/learning/
> >
> > All for vaporware, tho.
> >
>
> No one said rperl is vaporware, I said Perl::Types is. If you don't believe
> me, try running ?perl -e'use Perl::Types; my integer $foo = "L"'?

We're are in the process of extracting it from RPerl. So what.

>
>
> > > It really is a problem with Perl and Perl adoption and I don't know how
> > it
> > > can easily solved.
> > >
> > > But Perl was designed for *developer* efficiency and the Oshun data check
> > > project leans into that, hard.
> >
> > Ironically, what you are doing is extremely similar to Ada's
> > approach, part of which is called "design by contract". Ada has
> > full specifications on that and it's done by actual language
> > designers on US tax payer's dime. It's not bad, just not novel. It
> > seems a first pass on understanding how to apply Ada's approach in
> > describing the kinds of constraints you wish to describe would be
> > well worth the effort - and maybe a few academic papers. Were you
> > aware that Oshun is heading decidely into a space that has been
> > well specified by Ada?
> >
> > The last time I used Ada was in college, and it was for 1 semester.
> > It is an interesting languge, used even in real time systems like
> > avionics. So clearly it can be performant, but it also doens't have
> > the limitations perl does.
> >
> > Anyway, I suggestion you suggest you call Oshun what it is, "design
> > by contract", not only would more people understand at what level
> > it sits; but it would assist in the internal and external designs
> > by the mountains of existing implementations and specifications.
> > It might be novel in Perl, but it is not novel.
> >
>
> No, Oshun is not design by contract. Design by contract is fundamentally
> about checking code/transitions, not values.
>

Nobody actually knows what Oshun is proposing yet, even at this year's
TPFC, Curtis was still admittedly in the design phase. This is also indicated
by the nature of the discussion. I am not sure a specification even exists.

FWIW, I found this module linked on the Wikipedia page for DsC, which is from
the early 2000s. It is by Damian and I assume is an apple that falls not
far from the tree. Though Oshun is decidedly declarative, I suspect this
very old and experimental (looking) module might serve as some yard stick
to see if once a spec is fleshed out, how much DbC we can say it is.

https://metacpan.org/pod/Class::Contract#A-complete-example

Regardless, look at the Ada standard for declaring DbC and constraints on
data types and objects. This is what originally lead me to even see that it
might be called DbC. Best you can probably assert is that it's not DbC because
the spec is not on a firm foundation and it can't yet be determined.

It's not a bad thing Oshun is still in the design phase. But it also can't be
used to beat Perl::Types over the head because Perl::Types is a real thing (yes
currently tied to RPerl) and Oshun is not. It's also apples and oranges. I've
aleady linked the code in the RPerl. It's real enough that we are getting real
feedback outside of this thread, which I do very much appreciate.

So all y'all just need to stop gaslighting people into saying Perl::Types is
vaporware. Because this is the word that is being used, like I said in dark
echo chambers of ther perl-verse.

Cheers,
Brett

> Please stop acting like you're the one here to school people.
>
> > We do not make promises of code performance. We make promises of developer
> > > performance and data correctness. The amount of code you would have to
> > > write to manually verify all of these assumptions is ridiculous, so many
> > > developers skip that entirely.
> >
> > Ignoring actual performance unwise. I am not suggesting pre-mature
> > optimizing the tricky stuff, but the obvious stuff, yes. It also
> > immediately loses most of your potential users. So what's the point
> > in hedging AGAINST performance? Makes me think you're not really
> > serious.
> >
>
> Are you?
>
> Leon

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
* Leon Timmermans <fawaka@gmail.com> [2023-08-23 00:29:39 +0200]:

> On Wed, Aug 23, 2023 at 12:22?AM Christian Walde <walde.christian@gmail.com>
> wrote:
>
> > that said: is there a known pause policy regarding your identified
> > behavior of squatting?
> >
>
> ?Perl reserves all lowercase namespaces for pragmas. That doesn't mean you
> can't write a pragma, but you should get the blessing of p5p (
> perl5-porters@perl.org).? [1]

Or as it were, for 21 years, PAUSE.

>
> So there is a contingency policy for namespaces like these, though I don't
> think we've ever used it.
>
> Leon
>
> 1:
> https://pause.perl.org/pause/query?ACTION=pause_namingmodules#All_lowercase_name

Sure let me know when you do something about types.pm.

Cheers,
Brett

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, 23 Aug 2023 00:37:20 +0200, Oodler 577 <oodler577@sdf-eu.org> wrote:

> * Leon Timmermans <fawaka@gmail.com> [2023-08-23 00:29:39 +0200]:
>
>> On Wed, Aug 23, 2023 at 12:22?AM Christian Walde <walde.christian@gmail.com>
>> wrote:
>>
>> > that said: is there a known pause policy regarding your identified
>> > behavior of squatting?
>>
>> ?Perl reserves all lowercase namespaces for pragmas. That doesn't mean you
>> can't write a pragma, but you should get the blessing of p5p (
>> perl5-porters@perl.org).? [1]

that is a quite different thing from a squatting policy, but very applicable here, thanks leon :)

> Or as it were, for 21 years, PAUSE.

what does this mean?

>> So there is a contingency policy for namespaces like these, though I don't
>> think we've ever used it.
>
> Sure let me know when you do something about types.pm.

the order of operations here is somewhat different

optimally you would've presented a proposal, gained concensus on it, and with agreement have uploaded a distribution to CPAN, thus grabbing the namespaces will did already grab ( https://pause.perl.org/pause/authenquery?ACTION=peek_perms&pause99_peek_perms_by=a&pause99_peek_perms_query=wbraswell&pause99_peek_perms_sub=Submit )

(you did not do that, you just grabbed them without asking anyone)

then, as well with said concensus, contacted pause admins to enact said concensus on the permissions of items conflicting with yours

if you are asking for pre-concensus unilateral action, then your perl-types dist would currently also be a target

otherwise you will need to ask for this to be enacted, and once concensus has given the go-ahead, you will receive the appropriate replies

--
With regards,
Christian Walde
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Tue, Aug 22, 2023 at 5:34?PM Oodler 577 via perl5-porters
<perl5-porters@perl.org> wrote:
>
> Nobody actually knows what Oshun is proposing yet, even at this year's
> TPFC, Curtis was still admittedly in the design phase. This is also indicated
> by the nature of the discussion. I am not sure a specification even exists.
>

Pardon me for asking, but are you calling Curtis a liar? Otherwise, I
must assume you are behind on your emails as I was able to find, only
slightly upthread, where Curtis says:

> We offer:
> [...]
> A full, draft spec which needs to be updated when we agree on syntax

After a brief conversation with a web-search tool about "perl Oshun
specification", I was quickly reading:

https://github.com/Perl-Apollo/oshun/blob/main/lib/Data/Checks/Specification.pod

What sort of research did you do before making the above statement?

I ask because you have recently reminded us of our responsibilities
toward quality of discourse, here on p5p.

> FWIW, I found this module linked on the Wikipedia page for DsC, which is from

Thanks.
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
* Corwin Brust <corwin@bru.st> [2023-08-22 19:51:42 -0500]:

> On Tue, Aug 22, 2023 at 5:34?PM Oodler 577 via perl5-porters
> <perl5-porters@perl.org> wrote:
> >
> > Nobody actually knows what Oshun is proposing yet, even at this year's
> > TPFC, Curtis was still admittedly in the design phase. This is also indicated
> > by the nature of the discussion. I am not sure a specification even exists.
> >
>
> Pardon me for asking, but are you calling Curtis a liar?
> Otherwise, I must assume you are behind on your emails as I was able to find,
> only slightly upthread, where Curtis says:

Not here, no. How is that.

I called him a liar in another thread, but about his characterization
of Perl::Types implying it was vaporware. We've discussed this.

Oshun is clearly in flux, have you seen Curtis' keynote? He says
as much. Maybe not in those words, but it's almost entirely
speculative.

Here's the part of the talk that Curtis presented as a budding
thought, and which made it clear to Will (and I) that Perl::Types
needed to be brought up now. Not later. Will and I were both sitting
in the room watching the talk. You will hear at some point in the
video, Will is commenting to Curtis that Perl already has a type
system. That type system is not Perl::Types, but Perl::Types takes
advantage of the existing "types" system. Therefore it's a hugely
missed opportunity to ignore that it exists. And it is real.

https://youtu.be/uT0S-jfO1mE?feature=shared&t=2002

It's a good talk, I suggest you watch the full thing.

>
> > We offer:
> > [...]
> > A full, draft spec which needs to be updated when we agree on syntax
>
> After a brief conversation with a web-search tool about "perl Oshun
> specification", I was quickly reading:
>
> https://github.com/Perl-Apollo/oshun/blob/main/lib/Data/Checks/Specification.pod
>
> What sort of research did you do before making the above statement?

I follow the conversations on their Github discussion forum.

Had not seen the "spec". But even if I had, it just confirms what
I was saying. This is not knock against the project, it's in a very
early phase. That's why Perl::Types is getting brought up now.
The Oshun spec, says:

=head1 STATUS

This is very early alpha code, designed to prototype an idea that might one
day be a core feature of Perl.

Every aspect of this module is subject to sudden and radical change,
from the check syntax itself, to the names of the various checks,
to their essential behaviours, features, and limitations.

B<DO I<NOT> USE THIS MODULE IN PRODUCTION CODE.>

>
> I ask because you have recently reminded us of our responsibilities
> toward quality of discourse, here on p5p.

Thank you for pointing out Curtis shared the link.

Cheers,
Brett

>
> > FWIW, I found this module linked on the Wikipedia page for DsC, which is from
>
> Thanks.
>

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
* Christian Walde <walde.christian@gmail.com> [2023-08-23 00:53:12 +0200]:

> On Wed, 23 Aug 2023 00:37:20 +0200, Oodler 577 <oodler577@sdf-eu.org> wrote:
>
> > * Leon Timmermans <fawaka@gmail.com> [2023-08-23 00:29:39 +0200]:
> >
> > > On Wed, Aug 23, 2023 at 12:22?AM Christian Walde <walde.christian@gmail.com>
> > > wrote:
> > >
> > > > that said: is there a known pause policy regarding your identified
> > > > behavior of squatting?
> > >
> > > ?Perl reserves all lowercase namespaces for pragmas. That doesn't mean you
> > > can't write a pragma, but you should get the blessing of p5p (
> > > perl5-porters@perl.org).? [1]
>
> that is a quite different thing from a squatting policy, but very applicable here, thanks leon :)
>
> > Or as it were, for 21 years, PAUSE.
>
> what does this mean?

I didn't think that p5p controlled CPAN, PAUSE Admins (or whatever they are called) do.

>
> > > So there is a contingency policy for namespaces like these, though I don't
> > > think we've ever used it.
> >
> > Sure let me know when you do something about types.pm.
>
> the order of operations here is somewhat different
>
> optimally you would've presented a proposal, gained concensus on it, and with agreement have uploaded a distribution to CPAN, thus grabbing the namespaces will did already grab ( https://pause.perl.org/pause/authenquery?ACTION=peek_perms&pause99_peek_perms_by=a&pause99_peek_perms_query=wbraswell&pause99_peek_perms_sub=Submit )
>
> (you did not do that, you just grabbed them without asking anyone)
>
> then, as well with said concensus, contacted pause admins to enact said concensus on the permissions of items conflicting with yours
>
> if you are asking for pre-concensus unilateral action, then your perl-types dist would currently also be a target
>
> otherwise you will need to ask for this to be enacted, and once concensus has given the go-ahead, you will receive the appropriate replies

Your turn to explain what you're trying to tell me.

Cheers,
Brett

> --
> With regards,
> Christian Walde
>

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, 23 Aug 2023 04:14:03 +0200, Oodler 577 <oodler577@sdf-eu.org> wrote:

>> > > So there is a contingency policy for namespaces like these, though I don't
>> > > think we've ever used it.
>> >
>> > Sure let me know when you do something about types.pm.
>>
>> the order of operations here is somewhat different
>>
>> [...]
>
> Your turn to explain what you're trying to tell me.

unless you do something different, you won't see anything being done

--
With regards,
Christian Walde
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On 2023-08-22 11:43 a.m., Oodler 577 via perl5-porters wrote:
> ... your DbC efforts
> (which btw do not conflict with Perl::Types, a point we've made).
> Perhaps you can show where Perl::Types, as we've demonstrated would
> conflict with Oshun. I am not suggesting they are directly composable,
> but Perl::Types could definitely assist you where otherwise you'd
> just be using regular expressions everywhere (behind some sugar,
> of course).

That last thing you said about "otherwise you'd just be using regular
expressions everywhere" seems like an unfounded assumption to me.

While Perl::Types could serve as a foundation for Oshun, there's also no reason
at all that an Oshun implementation couldn't be written against Perl directly
AND Oshun would use exactly the same methods Perl::Types would to access the
"real" Perl type system directly and NOT using regular expressions.

It is true that some other type implementations in Perl use regular expressions,
but Oshun is a design spec for user-visible syntax and behavior, and there's no
reason at all it would necessarily be implemented with regular expressions.

In fact I would assume the opposite, that an Oshun implementation being more
modern would attach to core Perl very closely and exploit directly everything
that Perl::Types would, and have the same performance potential.

I would expect Oshun to follow the same kind of path Corinna did, which yielded
a very tight and efficient implementation in principle.

-- Darren Duncan
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
* Darren Duncan <darren@darrenduncan.net> [2023-08-22 19:44:50 -0700]:

> On 2023-08-22 11:43 a.m., Oodler 577 via perl5-porters wrote:
> > ... your DbC efforts
> > (which btw do not conflict with Perl::Types, a point we've made).
> > Perhaps you can show where Perl::Types, as we've demonstrated would
> > conflict with Oshun. I am not suggesting they are directly composable,
> > but Perl::Types could definitely assist you where otherwise you'd
> > just be using regular expressions everywhere (behind some sugar,
> > of course).
>
> That last thing you said about "otherwise you'd just be using regular
> expressions everywhere" seems like an unfounded assumption to me.
>
> While Perl::Types could serve as a foundation for Oshun, there's also no
> reason at all that an Oshun implementation couldn't be written against Perl
> directly AND Oshun would use exactly the same methods Perl::Types would to
> access the "real" Perl type system directly and NOT using regular
> expressions.
>
> It is true that some other type implementations in Perl use regular
> expressions, but Oshun is a design spec for user-visible syntax and
> behavior, and there's no reason at all it would necessarily be implemented
> with regular expressions.
>
> In fact I would assume the opposite, that an Oshun implementation being more
> modern would attach to core Perl very closely and exploit directly
> everything that Perl::Types would, and have the same performance potential.
>
> I would expect Oshun to follow the same kind of path Corinna did, which
> yielded a very tight and efficient implementation in principle.

Why would you expect that?

Cheers,
Brett

>
> -- Darren Duncan
>

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On 2023-08-22 8:13 p.m., Oodler 577 via perl5-porters wrote:
>> I would expect Oshun to follow the same kind of path Corinna did, which
>> yielded a very tight and efficient implementation in principle.
>
> Why would you expect that?

I would expect Oshun to not use regular expressions to evaluate fundamental
types because that is the best solution. If Perl::Types can find a better way
than using regular expressions, then Oshun can apply the same better solution
directly as well. Why would this not be a reasonable assumption?

-- Darren Duncan
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
Oshun has undergone a great deal of change and development since TPRC,
that's how fast it's moving. Using the keynote as an indicator to the
progress of the project misses quite a lot of work/discussion that's
happened since.

Avery

On Wed, 23 Aug 2023 at 13:41, Oodler 577 via perl5-porters <
perl5-porters@perl.org> wrote:

> * Corwin Brust <corwin@bru.st> [2023-08-22 19:51:42 -0500]:
>
> > On Tue, Aug 22, 2023 at 5:34?PM Oodler 577 via perl5-porters
> > <perl5-porters@perl.org> wrote:
>
> Oshun is clearly in flux, have you seen Curtis' keynote? He says
> as much. Maybe not in those words, but it's almost entirely
> speculative.
>
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
* Avery Adams <oldtechaa@gmail.com> [2023-08-23 15:45:09 +1200]:

> Oshun has undergone a great deal of change and development since TPRC,
> that's how fast it's moving. Using the keynote as an indicator to the
> progress of the project misses quite a lot of work/discussion that's
> happened since.

Thank you, that's my point.

Brett

>
> Avery
>
> On Wed, 23 Aug 2023 at 13:41, Oodler 577 via perl5-porters <
> perl5-porters@perl.org> wrote:
>
> > * Corwin Brust <corwin@bru.st> [2023-08-22 19:51:42 -0500]:
> >
> > > On Tue, Aug 22, 2023 at 5:34?PM Oodler 577 via perl5-porters
> > > <perl5-porters@perl.org> wrote:
> >
> > Oshun is clearly in flux, have you seen Curtis' keynote? He says
> > as much. Maybe not in those words, but it's almost entirely
> > speculative.
> >

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
* Darren Duncan <darren@darrenduncan.net> [2023-08-22 20:29:38 -0700]:

> On 2023-08-22 8:13 p.m., Oodler 577 via perl5-porters wrote:
> > > I would expect Oshun to follow the same kind of path Corinna did, which
> > > yielded a very tight and efficient implementation in principle.
> >
> > Why would you expect that?
>
> I would expect Oshun to not use regular expressions to evaluate fundamental
> types because that is the best solution. If Perl::Types can find a better
> way than using regular expressions, then Oshun can apply the same better
> solution directly as well. Why would this not be a reasonable assumption?

I still don't follow. It's okay, I know poeple are dead sick of this thread.

Cheers,
Brett

>
> -- Darren Duncan

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, Aug 23, 2023 at 12:21?AM Avery Adams <oldtechaa@gmail.com> wrote:
>
> Resending to list.
>
> ---------- Forwarded message ---------
> From: Avery Adams <oldtechaa@gmail.com>
> Date: Wed, 23 Aug 2023 at 15:55
> Subject: Re: PPC Elevator Pitch for Perl::Types
> To: Darren Duncan <darren@darrenduncan.net>
>
>
> With Oshun providing dynamic "types", I would have to imagine it would be less performant even using the same approach to data checking, simply because the types aren't predefined with known structure/characteristics. Would that not be the case?

"It depends." I don't think the types themselves (or numbers known at
compile time) are the problem.

I'm not an expert here and I'm seriously hoping someone steps up to
call me an idiot and wrong but as best I can tell the performance hit
isn't entirely the assertion check itself, it's the slow down on
_everything_ that simply having the assertion causes. As was mentioned
in this thread there are only so many ways to attach extra behavior to
a variable in Perl and we've spent since 1995 (or possibly 1985)
optimizing the common case of having no extra behavior. The minute you
add a type annotation we need to include a way to look up the
assertion check, which means we no longer have a "simple" SV (or AV or
HV) and all the optimized code isn't used.

An implementation of anything like Oshun would, I think, have to work
roughly the same way as an implementation of Perl::Types would, I
think, have to work. You'd have to annotate the variable to call an
extra function during runtime when the variable is set. Whether that
function is a CV defined at compile time, or one of the SvOK macros …
you still have to link to it via magic vtable or something like that
and you lose every optimized hotpath for variables that don't have
magic attached to them. So the performance becomes vaguely the same
regardless of how the structure of types are predefined / known at
compile time.

Both Oshun and Perl::Types will, at least initially[1], slow down any
application that enables them unless/until some kind of Optimizer is
written to compile typed Perl into untyped Perl so that the core
runtime can "just work" (or we fix the hotpaths to allow typed code
but I don't that isn't at least as much work as an optimizer, I just
know _I_ can't/won't write it)

Additionally because Perl allows perfectly valid code like:

my $foo = int(rand(2)) % 2) ? \1 : [];
say $$foo; # dies 50% of the time

The correctness is only going to be seen at runtime with a slightly
better error message after this is re-written to:

my ScalarRef $foo = int(rand(2)) %2 ? \1 : []; # dies 50% of the time
say $$foo;

Or more the more sneaky and common:

my Int $foo = 1;
say $foo . " coercions have occured"; # boom?

($foo is no longer an SvIV but Perl::Types doesn't say if this should
be an error or not, but the next time our assertion check is executed
it'll blow up. I believe the current spec for Oshun says it's not an
error and you've got to be OK with that as a limitation.)

Any optimizer we write will need to be smart enough to allow these
kinds of things through with enough of the type system left to throw
intelligent errors, otherwise we're just begging for support tickets.
This means that _some_ of our variables will probably still have some
kind of magic attached to them and we still take a performance hit,
even with optimized code, but _maybe_ the optimizations are enough to
balance that out and/or increase performance? Who knows, it's a future
that's as-yet unwritten.

So from this list:

* increased performance
* code correctness
* type safety (type checking)
* memory safety (bounds checking)
* documentation of code intent
* potential for polymorphism
* potential for derived or synthetic types

Realistically all I've seen evidence for in initially from _either_
Oshun or Perl::Types is[2]:

* (type checking)
* documentation of code intent
* potential for polymorphism

I think long-term it opens the door for experiments with more
optimizations once we have enough annotated Perl in the world, but
nobody should be selling that as an advantage right now.

Personally I see this as "worth it" but only if I'm not limited to
C's type-bestiary, so Perl::Types isn't really interesting to me.

-Chris

[1]: Someone might possibly write an optimizer that takes advantage of
the type annotations to improve performance, but that's neither simple
nor easy.
[2]: 'memory safety (bounds checking)' and 'potential for derived or
synthetic types' aren't really problems Perl currently faces afaict
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
> Re: PPC Elevator Pitch for Perl::Types
> Thread Previous | Thread Next
> From: Dave Mitchell
> Date: August 22, 2023 10:03
> Subject: Re: PPC Elevator Pitch for Perl::Types
> Message ID: ZOSHzZ2SS1lMJdZy@iabyn.com

> On Tue, Aug 22, 2023 at 04:19:04AM +0000, Oodler 577 via perl5-porters wrote:
> > Yes you are correct, the current mechanism for enabling type-checking
> > for subroutine calls is essentially a type of source filter. As
> > mentioned in our first reply:
> >
> > > > The Perl compiler currently supports type enforcement for subroutine calls, so that is our starting point for Perl::Types.
> >
> > This source-filter-like functionality is currently contained in
> > the Perl compiler's file `Class.pm`

> So just for the avoidance of doubt, is the proposal that Perl::Types,
> when running in a perl (rather than RPerl) environment, will use perl's
> actual source filter mechanism, or that it will use some other
> "essentially a type of source filter" thing?

> If the latter, please expand.

It is not an actual source filter as documented in `perlfilter`,
although it is the same general concept. As mentioned in the
previous response, _"this source-filter-like functionality is
currently contained in the Perl compiler's file `Class.pm` and is
triggered by including `use RPerl;` in a Perl source code file."_
You can see the filter-like implementation in the link and code
snippet from our last response:

https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/CompileUnit/Module/Class.pm#L673-715

```perl
if ( $CHECK eq 'ON' ) {
my $i = 0; # integer
foreach my $subroutine_argument ( @{$subroutine_arguments} ) {
# only enable type-checking for arguments of supported type;
# NEED UPGRADE: enable checking of user-defined Class types & all other remaining RPerl types
if (exists $TYPES_SUPPORTED->{$subroutine_argument->[0]}) {
$subroutine_arguments_check_code .= q{ rperltypes::} . $subroutine_argument->[0] . '_CHECK( $_[' . $i . '] );' . "\n"; # does work, hard-code all automatically-generated type-checking code to 'rperltypes::' namespace
}
$i++;
}

activate_subroutine_args_checking( $package_name, $subroutine_name, $subroutine_type, $subroutine_arguments_check_code, $module_filename_long );
$inside_subroutine = 0;
$subroutine_arguments_line = q{};
}
```

As mentioned, _"you can see that both `ON` and `TRACE` call
`activate_subroutine_args_checking()`, which is where the type-checking
calls are inserted into a new subroutine, that wraps around the
original un-type-checked subroutine"_:

https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/CompileUnit/Module/Class.pm#L1016-1183

```perl
# re-define subroutine call to include type checking code; new header style
do
{
no strict;

# create unchecked symbol table entry for original subroutine
*{ $package_name . '::__UNCHECKED_' . $subroutine_name } = \&{ $package_name . '::' . $subroutine_name }; # short form, symbol table direct, not strict

# delete original symtab entry,
undef *{ $package_name . '::' . $subroutine_name };

# re-create new symtab entry pointing to checking code plus unchecked symtab entry
$subroutine_definition_code .=
'*' . $package_name . '::' . $subroutine_name . ' = sub { ' .
$subroutine_definition_diag_code .
($subroutine_arguments_check_code or "\n") .
' return ' . $package_name . '::__UNCHECKED_' . $subroutine_name . '(@ARG);' . "\n" . '};';

# create new checked symtab entries, for use by Exporter
$check_code_subroutine_name = $package_name . '::__CHECK_CODE_' . $subroutine_name;
$subroutine_definition_code .= "\n" . '*' . $package_name . '::__CHECKED_' . $subroutine_name . ' = \&' . $package_name . '::' . $subroutine_name . "\n" . ';';

$subroutine_definition_code .= "\n" . '*' . $check_code_subroutine_name . ' = sub {' . "\n" . ' my $retval ' . q{ =<<'EOF';} . "\n" . $subroutine_arguments_check_code . "\n" . 'EOF' . "\n" . '};' . "\n";
};

eval($subroutine_definition_code) or (RPerl::diag('ERROR ECOPR02, PRE-PROCESSOR: Possible failure to enable type checking for subroutine ' . $package_name . '::' . $subroutine_name . '(),' . "\n" . $EVAL_ERROR . "\n" . 'not croaking'));
if ($EVAL_ERROR) { croak 'ERROR ECOPR03, PRE-PROCESSOR: Failed to enable type checking for subroutine ' . $package_name . '::' . $subroutine_name . '(),' . "\n" . $EVAL_ERROR . "\n" . 'croaking'; }
```

> If the former, note that we generally regard the perl source filter
> mechanism as deeply flawed, and wouldn't recommend its use in production
> code. The basic problem comes down to the old mantra that "only perl can
> parse Perl". A source filter may correctly parse the source 99.9% of the
> time, but on those 0.1% occasions, it will get something wrong. Maybe it
> will get the start of a // operator confused with the start of a pattern.
> Or maybe it will trip over some complex code embeded into a pattern:
> /...(?{ $x = '/'; }) .../. Or whatever. At that point, code will get
> injected at the wrong point into the source, and the end user gets a
> compile error from code that isn't even in their source, which is
> completely mystifying and hard to debug.

> Switch.pm used source filters, and it was the cause of an endless stream
> of tickets. It was eventually deprecated and removed from core in 5.14.0.

Yes we agree this could be a source of problems.

Rather than using a source filter (or similar mechanism as detailed
above), can you please suggest a more stable and reliable
implementation?

> > Regarding your `my number $x; $x = 'foo';` example, this will
> > require the use of a `tie` or similar mechanism

> Again, this is very vague. Do you actually mean perl's tie / magic
> mechanism? If not, what "similar mechanism" are you proposing to use?

As mentioned, _"in the past, we have always simply allowed the
C(++) compiler to provide this functionality for us; however, this
will have to be explicitly implemented when `Perl::Types` is
refactored into its own distribution."_

Thus, we are not committed to any specific implementation, as long
as we choose a mechanism that allows us to (eventually) handle
_"arbitrarily-nested data structures"_ by _"intercepting any
modifications to internal elements and calling `foo_CHECK()` or
`foo_CHECKTRACE()` for each change."_

> The problem with using actual ties, is that they make the variable very
> slow, even if the actual tie methods such as FETCH() are XS code. That's
> because a lot of code paths in the perl interpreter have optimisations for
> non-magic values. For example, look at pp_add() in pp_hot.c in the perl
> source. This implements perl's '+' operator. Obviously in general the two
> operands can be anything - ints, ,nums, strings, magic values, overloaded
> objects etc, and mixtures thereof. But in pp_add(), the first thing it
> does it check the flags of the two operands, and says:

> If they are both non magical and non ref, and if both are either
> simple ints or simple nums, then just add the two values, check they
> haven't overflowed, set the return value and return. Otherwise go
> through the complex 200-lines-of-code path which handles magic, mixed
> types etc.

> So if, for example, an integer variable was marked with get magic, it
> would become a lot slower when being added. Similar considerations apply
> in many places.

> Also, once tie magic starts being applied to arrays and hashes, you start
> to hit edges cases. It's very had to make a tied aggregate behave *exactly*
> like a plain array/hash in all circumstances, even ignoring the slowdown.

Yes we agree this could also be a source of problems, plus slowdowns.

Rather than using `tie`, can you please suggest a more performant
and reliable implementation?

> > So, as mentioned in the original Elevator Pitch, we can "utilize
> > Perl data types to achieve a number of benefits including but not
> > limited to":
> >
> > * increased performance

> So how would you get increased performance? I've already pointed out that
> magic tends to slow things down, and the cost of calling a check routine
> will slow things down even further.

Adding data types to your Perl source code is the first step on
the path toward compiling your Perl source code, which can provide
anywhere from 10x to 400x (or more) runtime performance increase.
Yes you are correct that enabling type-checking will introduce
runtime overhead to interpreted Perl code, but that slowdown
disappears once your Perl code is fully compiled because the
type-checking is done at compile time rather than runtime.

For those who want type-checking for interpreted Perl code only,
we have done our best to minimize the runtime overhead by allowing
the developer to choose between `foo_CHECKTRACE()` and the slightly
faster `foo_CHECK()`. As mentioned, _"type checking is currently
controlled on a per-file basis using the `TYPE_CHECKING` preprocessor
directive"_:

https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/Test/TypeCheckingTrace/AllTypes.pm#L1-2

```perl
# [[[ PREPROCESSOR ]]]
# <<< TYPE_CHECKING: TRACE >>>
```

_"The `TYPE_CHECKING` directive can have a value of `OFF` for
disabled, `ON` to call the `foo_CHECK()` macros/functions, and
`TRACE` to call the `foo_CHECKTRACE()` macros/functions. The only
difference between `ON` and `TRACE` is the inclusion of the offending
subroutine and variable names for easier debugging."_

Furthermore, the type-checking is performed by C macros for scalar
data types, and by C functions (which call those underlying C
macros) for array and hash data structures, which is the fastest
possible solution we could find. We even re-implemented our original
scalar type-checking from C functions to C macros for increased
performance.

Here is an example of the fast (but now-deprecated) C functions
for checking the `number` type AKA `NV`:

https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/DataType/Number.cpp#L18-38

```c
// TYPE-CHECKING SUBROUTINES DEPRECATED IN FAVOR OF EQUIVALENT MACROS
void number_CHECK(SV* possible_number) {
if (not(SvOK(possible_number))) {
croak("\nERROR ENV00, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but undefined/null value found,\ncroaking");
}
if (not(SvNOKp(possible_number) || SvIOKp(possible_number))) {
croak("\nERROR ENV01, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but non-number value found,\ncroaking");
}
};
void number_CHECKTRACE(SV* possible_number, const char* variable_name, const char* subroutine_name) {
if (not(SvOK(possible_number))) {
croak("\nERROR ENV00, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but undefined/null value found,\nin variable %s from subroutine %s,\ncroaking",
variable_name, subroutine_name);
}
if (not(SvNOKp(possible_number) || SvIOKp(possible_number))) {
croak("\nERROR ENV01, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but non-number value found,\nin variable %s from subroutine %s,\ncroaking",
variable_name, subroutine_name);
}
};
```
Here is an example of the functionally-equivalent and even-faster
C macros, as mentioned in our first reply:

https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/DataType/Number.h#L137-149

```c
// [[[ TYPE-CHECKING MACROS ]]]
#define number_CHECK(possible_number) \
(not(SvOK(possible_number)) ? \
croak("\nERROR ENV00, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but undefined/null value found,\ncroaking") : \
(not(SvNOKp(possible_number) || SvIOKp(possible_number)) ? \
croak("\nERROR ENV01, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but non-number value found,\ncroaking") : \
(void)0))
#define number_CHECKTRACE(possible_number, variable_name, subroutine_name) \
(not(SvOK(possible_number)) ? \
croak("\nERROR ENV00, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but undefined/null value found,\nin variable %s from subroutine %s,\ncroaking", variable_name, subroutine_name) : \
(not(SvNOKp(possible_number) || SvIOKp(possible_number)) ? \
croak("\nERROR ENV01, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES:\nnumber value expected but non-number value found,\nin variable %s from subroutine %s,\ncroaking", variable_name, subroutine_name) : \
(void)0))
```

For those who want data types in their interpreted code as a form
of annotation only, they can set `TYPE_CHECKING` to `OFF` for even
better performance. You can always turn it back on later.

```perl
# [[[ PREPROCESSOR ]]]
# <<< TYPE_CHECKING: OFF >>>
```

For those who don't want data types in their Perl code at all...
just don't `use Perl::Types;`, it's that simple. Your code won't
be affected in anyway, and you can safely continue without any data
types of any kind, just like Perl has always been in the past.

> > * memory safety (bounds checking)

> Can you give an example of where currently perl isn't memory safe, but
> Perl::Types would make it so?

We are not currently aware of any such issues with the Perl
interpreter, and our goal is not to attempt to point out anything
wrong with the interpreter's memory management. Rather, this is
again primarily related to the need for memory bounds checking for
those who wish to compile their Perl code.

That being said, in the future it may certainly be possible for
the Perl interpreter to utilize data type and data structure
information to implement optimizations in memory and/or performance.

For example, a Perl array can declare its own specific maximum
index (length minus 1) during creation, which is used by the Perl
compiler (and subsequently the C(++) compiler) for standard memory
management purposes. In the following example, the declared
`arrayref` length is 4, with an `undef` being assigned to the
maximum index of 3 (`4 - 1`) in order to avoid `Useless use of
array element in void context` when `use warnings;` is enabled:

```perl
my integer::arrayref $foo->[4 - 1] = undef;
```

The current experimental syntax for declaring an `array` is very similar, but without the need for `undef` and with the unfortunate need for a temporary `$TYPED_foo` scalar:

```perl
my integer::array @foo = my $TYPED_foo->[4 - 1];
```

The Perl interpreter could potentially utilize the array's maximum
index to more effectively organize allocated memory, reduce calls
to garbage collection, increase efficiency of accessing contiguous
array elements, etc.

As with our previously-discussed pure-Perl `$RETURN_TYPE` syntax,
the current experimental syntax for declaring array lenths may
leave a bit to be desired, but it does not require any change to
the Perl parser and was the best we could come up with so far.
(Also, in the `arrayref` example the Perl interpreter actually
creates an anonymous array of length 4, while in the `array` example
it creates an array of length 1.)

Can you please suggest possible pure-Perl syntax alternatives for
specifying the various maximum indices of an arbitrarily-nested
`array` and `arrayref`, without requiring any changes to the existing
Perl internals?

> > * potential for polymorphism

> Please explain further.

There are many different styles or variations of polymorphism in
computer science. For the sake of brevity, we will only address
one style here: function overloading AKA ad hoc polymorphism.
These same ideas can likely be extended to include other styles of
polymorhism as well.

For example, imagine the following expansion of our original
`squared()` subroutine example:

```perl
#!/usr/bin/perl
use strict;
use warnings;

use Perl::Types;

sub squared {
{ my integer $RETURN_TYPE };
( my integer $base ) = @ARG;
return $base ** 2;
}

sub squared {
{ my number $RETURN_TYPE };
( my number $base ) = @ARG;
return $base * $base;
}

sub squared {
{ my string $RETURN_TYPE };
( my string $base ) = @ARG;
return $base x (length $base);
}

print squared(23), "\n";
print squared(21.12), "\n";
print squared('howdy'), "\n";
```

Wouldn't it be nice if we got this...

```
529
446.0544
howdyhowdyhowdyhowdyhowdy
```

... instead of this?

```
Subroutine squared redefined at ./sub_test.pl line 14.
Subroutine squared redefined at ./sub_test.pl line 20.
2323
21.1221.1221.1221.1221.12
howdyhowdyhowdyhowdyhowdy
```
What are your thoughts on this kind of polymorphism, function overloading based on argument and/or return value data type(s)?

> Ok, that was the technical side of things. Now on to the policy side.
> 20 years or so ago, perl went through a phase of adding lots of 'useful'
> modules to the perl core. This was widely seen as a mistake.

> First, it made a particular module seem to be officially endorsed.
> Hypothetically, "among several XML parser modules, we chosen this one as
> the best and the one you should use". When design flaws in XML::Parser
> (say) are discovered, and the general recommendation is to use
> XML::BetterParser instead, XML::Parser is still sitting in the perl core
> getting an unfair endorsement. And removing it from core is hard, because
> now lots of people used it, and they're using it because, well, we
> endorsed it!

Our goal is for Perl::Types to be the official data type system of
Perl, in the same exact way that Corinna is the official class
system of Perl. If a so-called "dual life" distribution is the
wrong way to achieve this, then we're fine with that.

> Second, if modules stop being actively maintained by their author(s) for
> whatever reason, then suddenly we become responsible for maintaining it.
> It's enough work just maintaining the core perl interpreter, without
> taking on extra responsibilities.

Yes we agree, which is why we have formed the Perl::Types Committee
and are in the process of training new Perl::Types developers to
avoid a low bus factor.

> Third, in these days of package managers etc, it's relatively easy for
> people to install the CPAN modules they want. They will also get the
> newest and best version by default, rather than using the old buggy version
> bundled with perl. So there is less good reason to bundle a package with
> perl.

Our goal is for Perl::Types (or its descendent) to be included in
every future version of Perl, in the same exact way that Corinna
will presumably be included in every future version of Perl. We
are fine with handling versioning in the same way as Corinna,
whatever that may be.

> So these days the policy is not to bundle CPAN modules with perl unless
> they are necessary, usually because they are needed as part of the tool
> chain. There have been very few new modules added to the perl core in the
> last 15 years or so that are capable of acting as standalone CPAN
> distributions instead.

> So the short answer is that even if Perl::Types really appealed to us, it
> is very unlikely that we would agree to bundle it. And I think we're
> far from a consensus yet that it appeals.

Since you have made a strong case against a dual-life distribution
being included in the Perl core, can you instead please explain
the specific process which Corinna followed to get merged into the
Perl interpreter?

Perhaps Perl::Types can act like Object::Pad, as the experimental
distribution out of which we can derive the desired Perl interpreter
code in the same way that Corinna was derived from Object::Pad?

> On a purely individual note, I am finding Perl::Types very unappealing so
> far.

Can you please give us a specific list of all the things you find
unappealing?

On Behalf of the _Perl::Types Committee_,
Brett Estrade

--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
> On Sep 2, 2023, at 12:11 AM, Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:
> Our goal is for Perl::Types to be the official data type system of
> Perl, in the same exact way that Corinna is the official class
> system of Perl.

Corinna isn’t a dual-life module, and Paul didn’t even start the conversation about what should go into core until Object::Pad had existed for a year or two (Object::Pad’s first release was October 2019, 5.37.0 was may 2022 … and Corinna was in a later release of the 5.37 series) so the conversation about *how* things could be implemented happened long before anything was brought to p5p. Additionally the features in 5.38 are a *very* stripped down subset of Object::Pad and Corinna, and literally the smallest subset we thought would be useful enough for people to experiment. There are several totally uncontroversial pieces that weren’t added to 5.38 because they weren’t necessary for the smallest possible solution (e.g. Roles).

Note that the PPC process started in the summer of 2021, so the formalities for Corinna weren’t entirely there. It used something more akin to the way Peter Martini got subroutine signatures in, but thankfully with far less drama because there are a lot more stop-gaps and processes to handle the system than there used to be. (The PPC process being a refactoring of these processes, partly I suspect inspired by the ad-hoc conversations that were happening around Corinna)

So if you want to follow this solution, build a working prototype and demonstrate that the ideas even work in principle in an environment that doesn’t depend on RPerl’s C++ compiler. Make some PRs to fix the short comings in the Perl interpreter that make implementing that proof of concept difficult. Then demonstrate how your code would work as a core system. All the while suffering through the sometimes heated arguments about syntax and semantics.

People have flat out said that your semantics won’t work but I haven’t yet seen a response to that.

For example what happens with this code:

my $var1 = 234;
my integer $var2 = 456; # Perl::Types
my $total = $var1 + $var2;

Without the RPerl compiler is this an error? Does $total inherit the integer type? What if I say `$total += 0.1`? What happens if instead of 234 I shift from @ARGV? What if $var1 is a dual var? What if it’s an overloaded object? What if it’s a tie? What if I call bultin::stringify on $var1 (i.e. join “”, $var1;)?

What’s your answer to people who are currently using Type::Tiny? Are they able to upgrade their types to your system? If not is that something you’re planning for?

Corinna had answers to its version of these questions by the time anything ended up on 5.37, and the stuff in 5.37 was the smallest sensible piece of it. I don’t pretend that the Corinna process was flawless, but if you want to follow its path you have about two years of proof of concept to get started on.

-Chris
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Wed, Aug 23, 2023 at 7:30?AM Chris Prather <chris@prather.org> wrote:

> "It depends." I don't think the types themselves (or numbers known at
> compile time) are the problem.
>
> I'm not an expert here and I'm seriously hoping someone steps up to
> call me an idiot and wrong but as best I can tell the performance hit
> isn't entirely the assertion check itself, it's the slow down on
> _everything_ that simply having the assertion causes. As was mentioned
> in this thread there are only so many ways to attach extra behavior to
> a variable in Perl and we've spent since 1995 (or possibly 1985)
> optimizing the common case of having no extra behavior. The minute you
> add a type annotation we need to include a way to look up the
> assertion check, which means we no longer have a "simple" SV (or AV or
> HV) and all the optimized code isn't used.
>

We have a distinction between get and set magic, so for scalars we can
actually do efficient shallow type checks, see Magic::Check on CPAN for an
implementation of this.

Arrays and hashes are still screwed though, and we made some API choices in
the past that make fixing it now more difficult than one would hope.


> Realistically all I've seen evidence for in initially from _either_
> Oshun or Perl::Types is[2]:
>
> * (type checking)
> * documentation of code intent
> * potential for polymorphism
>

Agreed.
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Sat, Sep 02, 2023 at 04:11:02AM +0000, Oodler 577 via perl5-porters wrote:
> > If the latter, please expand.
>
> It is not an actual source filter as documented in `perlfilter`,
> although it is the same general concept. As mentioned in the
> previous response, _"this source-filter-like functionality is
> currently contained in the Perl compiler's file `Class.pm` and is
> triggered by including `use RPerl;` in a Perl source code file."_
> You can see the filter-like implementation in the link and code
> snippet from our last response:

We seem to be misunderstanding each other at a fairly fundamental level.

My understanding (and please correct me if I'm wrong) is that your desired
eventual outcome of this discussion is that a distribution called
Perl:Types will be available on CPAN, and will also bundled into the perl
distribution, so that someone with a standard perl install can type into
their code something like:

use Perl::Types;
my integer $x = f(); # croaks if f() doesn't return an int.

This is independent of the existence of RPerl - i.e. some code from RPerl
may be incorporated into Perl::Types source, but the perl use isn't
required to install RPerl or use any of the weird RPerl syntax.

So, with that understanding, I've expressed curiosity as to how you are
going to implement this functionality using only the resources available
in perl. You said "Source filters". I said that was a bad idea. You've now
said "it's something similar to a source filter - look at this RPerl
code".

Why should I look at RPerl code? I'm not interested in RPerl. I Don't like
RPerl.

Do you believe it is possible to implement Perl::Types in perl? If so, how?
If not, are you suggesting proposals for new hooks or APIs that should be
incorporated into perl to make adding type systems easier? Or what?
I really have no idea what it is you're asking.

> Yes we agree this could be a source of problems.
>
> Rather than using a source filter (or similar mechanism as detailed
> above), can you please suggest a more stable and reliable
> implementation?

I have no idea. It may not be possible. It's not my problem.


> Rather than using `tie`, can you please suggest a more performant
> and reliable implementation?

No I can't. I haven't got a clue. I've spent 20 years working on the
internals of perl, and I think what you are requesting is a very difficult
to solve problem that may well have no solution.

> Adding data types to your Perl source code is the first step on
> the path toward compiling your Perl source code, which can provide
> anywhere from 10x to 400x (or more) runtime performance increase.

Ah yes, sprinkle on a bit of magic pixie dust and suddenly perl can be
made 400x faster.

> Yes you are correct that enabling type-checking will introduce
> runtime overhead to interpreted Perl code, but that slowdown
> disappears once your Perl code is fully compiled because the
> type-checking is done at compile time rather than runtime.

That way lies RPerl, surely?

> For those who want type-checking for interpreted Perl code only,
> we have done our best to minimize the runtime overhead by allowing
> the developer to choose between `foo_CHECKTRACE()` and the slightly
> faster `foo_CHECK()`. As mentioned, _"type checking is currently
> controlled on a per-file basis using the `TYPE_CHECKING` preprocessor
> directive"_:

I don't understand that all all. Please stop just pointing at random bits
of RPerl code which I am completely unfamiliar with and expecting that to
be an explanation.

> > > * memory safety (bounds checking)
>
> > Can you give an example of where currently perl isn't memory safe, but
> > Perl::Types would make it so?
>
> We are not currently aware of any such issues with the Perl
> interpreter, and our goal is not to attempt to point out anything
> wrong with the interpreter's memory management. Rather, this is
> again primarily related to the need for memory bounds checking for
> those who wish to compile their Perl code.

So using Perl::Types doesn't actually add any value to user's code as
regards memory safety.

> Can you please suggest possible pure-Perl syntax alternatives for
> specifying the various maximum indices of an arbitrarily-nested
> `array` and `arrayref`, without requiring any changes to the existing
> Perl internals?

Again, stop trying to make everything my responsibility.

> What are your thoughts on this kind of polymorphism, function overloading based on argument and/or return value data type(s)?

I don't have any strong opinions on it, but personally I don't see what
value it adds. It seems to be that, after adding a type system which
unduly limits the flexibility of your code, adding polymorphism based on
type just allows you to then remove *some* of that inconvenience.

I like the fact that in perl I can throw an int or a float or
string at a function, and it will already always do the Right Thing.
In perl I can write

while (<>) {
$foo += $1 if /foo=(\d+)/;
}

without having to worry about string to integer conversions or whatever.

> > On a purely individual note, I am finding Perl::Types very unappealing so
> > far.
>
> Can you please give us a specific list of all the things you find
> unappealing?

Well, the basic problem is that we still don't know what semantics
Perl::Types is supposed to provide or how it will be implemented.

So my objections are partly conjectural. But IIUC, RPerl's "type" system
is really just the CPU-level type system. I.e. what you get in C etc,
where an int is a simple 32-bit or 64-bit entity, which is fast but unsafe.

In C, if you do

int i = 0x7fffffffffffffff;
i *= 4;
printf "%d\n", i;

then you'll get some sort of wrapped-around value.

In perl, if you do

my $i = 0x7fffffffffffffff;
$i *= 4;
printf "%s\n", $i;

you get

3.68934881474191e+19

because internally, perl goes to great lengths to avoid overflows and loss
of precision, automatically converting internally between signed int,
unsigned int and doubles etc.

So I'm not keen on the idea of downgrading perl's dynamic type system into
a C-style type system.

In terms of making perl go a lot faster, I have various ideas, but little
time to realise them - there are always too many basic things to fix.

But I much prefer the idea of keeping perl as *perl* (dynamic typing etc)
and let the interpreter do the clever stuff: such as speculative execution
branches where perl assumes (based on code analysis and previous calls
to that code position) that the result will be an integer, and so skips
using full-blown SVs and just does direct integer arithmetic. If at some
point during execution an overflow is detected or whatever, then perl
jumps back to a checkpoint, and this time takes the "heavy" branch using
full-blown SVs etc.

So in something like $a[$x+$y*$z], perl detects that $x, $y and $z are
usually integer values, and takes a short-cut. If that doesn't work out,
then it still gets the right result, just more slowly.

So the user gets the performance benefits without having to rewrite
all their code to include 'integer' declarations everywhere.

As a final caveat, note that I'm more of an internals guy than a language
design guy. So my views on proposed new language features shouldn't be
taken too seriously. But if I say that a particular proposal will be hard
or impossible to implement, take that seriously.

--
The Enterprise successfully ferries an alien VIP from one place to another
without serious incident.
-- Things That Never Happen in "Star Trek" #7
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
(originally sent privately, sent to list on explicit request by oodler)

On Sat, 02 Sep 2023 06:11:02 +0200, Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:

> https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/CompileUnit/Module/Class.pm#L673-715

fwiw, some of the rather muted enthusiasm you're seeing for this project stems from the fact that (corroborated by several random perl devs i polled) this code looks harder to maintain than it should be, seemingly not being deduplicated, and not like native perl code at all

it feels like it was written by somebody who knows a different programming language really well and preferred not to get too familiar with perl

here's code that does somewhat similar work, but in a way that inspires confidence

https://metacpan.org/release/HAARG/Moo-2.005005/source/lib/Method/Generate/Accessor.pm#L429

--
With regards,
Christian Walde
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
* Christian Walde <walde.christian@gmail.com> [2023-09-04 10:08:13 +0200]:

> (originally sent privately, sent to list on explicit request by oodler)
>
> On Sat, 02 Sep 2023 06:11:02 +0200, Oodler 577 via perl5-porters <perl5-porters@perl.org> wrote:
>
> > https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/CompileUnit/Module/Class.pm#L673-715
>
> fwiw, some of the rather muted enthusiasm you're seeing for this project stems from the fact that (corroborated by several random perl devs i polled) this code looks harder to maintain than it should be, seemingly not being deduplicated, and not like native perl code at all

The results of your informal poll sound udderly ridiculous.

>
> it feels like it was written by somebody who knows a different programming language really well and preferred not to get too familiar with perl
>
> here's code that does somewhat similar work, but in a way that inspires confidence
>
> https://metacpan.org/release/HAARG/Moo-2.005005/source/lib/Method/Generate/Accessor.pm#L429

Okay, thanks.

Cheers,
Brett

>
> --
> With regards,
> Christian Walde

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
On Mon, 04 Sep 2023 23:44:04 +0200, Oodler 577 <oodler577@sdf-eu.org> wrote:

>> > https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/CompileUnit/Module/Class.pm#L673-715
>>
>> fwiw, some of the rather muted enthusiasm you're seeing for this project stems from the fact that (corroborated by several random perl devs i polled) this code looks harder to maintain than it should be, seemingly not being deduplicated, and not like native perl code at all
>The results of your informal poll sound udderly ridiculous.

why? :)

--
With regards,
Christian Walde
Re: PPC Elevator Pitch for Perl::Types [ In reply to ]
* Christian Walde <walde.christian@gmail.com> [2023-09-05 01:59:20 +0200]:

> On Mon, 04 Sep 2023 23:44:04 +0200, Oodler 577 <oodler577@sdf-eu.org> wrote:
>
> > > > https://metacpan.org/release/WBRASWELL/RPerl-7.000000/source/lib/RPerl/CompileUnit/Module/Class.pm#L673-715
> > >
> > > fwiw, some of the rather muted enthusiasm you're seeing for this project stems from the fact that (corroborated by several random perl devs i polled) this code looks harder to maintain than it should be, seemingly not being deduplicated, and not like native perl code at all
> > The results of your informal poll sound udderly ridiculous.
>
> why? :)

Because it's BS. Get it? Udderly BS? xD

Cheers,
Brett

>
> --
> With regards,
> Christian Walde

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native