in reply to Re^6: Reason for this discrepancy with scalar?
in thread Reason for this discrepancy with scalar?

> So I'm sceptical that putting in effort to make perl record the initial type

Well - as I just remembered - at least we don't need a new flag, but a type attribute.

my TYPE VARLIST

This obscure feature of my was already there since the very beginning of Perl 5

> is going to help serialisation as much as people expect.

I think not only serialization could profit here.

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^8: Reason for this discrepancy with scalar?
by dave_the_m (Monsignor) on Mar 16, 2024 at 17:35 UTC
    But lexical types largely don't do what people expect; in particular, they don't stop something which isn't an Int or whatever from being assigned to the lex var; nor do they coerce the assigned value to that type.

    In general, adding types to perl is a big topic which tends to trigger the occasional heated discussion on p5p and elsewhere.

    Dave.

      Yes I remember digging into it and the fields Pragma.

      And ....

      # this will generate a compile-time error my Foo $foo = Foo->new;

      I could see a use case in extending this already existing syntax for other purposes, like

      • allowing to translate a subset of Perl to inline C
      • helping IDEs to intellisense method expansions
      • defining an initial type (e.g. for serializers ; sic)

      But probably I'm naive.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery