llancet has asked for the wisdom of the Perl Monks concerning the following question:

Why Perl 5 don't have compile-time type restriction?
If some people don't want it, it may be designed to be selectable, likeuse strict;. Is that very hard to implement?

Replies are listed 'Best First'.
Re: Perl and Type restriction
by BrowserUk (Patriarch) on Mar 21, 2010 at 12:22 UTC

    If it was designed into the language from the ground up, as it is (at least to some extent) with Perl 6, then it is a reasonable thing to implement.

    Trying to retrofit it to Perl 5 would be near impossible.

    The best you could hope to do is use something like Moose to define your own classes for all the basic types, and then write all your programs completely in terms of those constructed types eshewing all of Perl's built-in types and libraries. Besides all the work that would entail--are you up for it to get what you want?--you wouldn't like the results.

    And what would it leave you? It wouldn't be Perl. So why use Perl to program in a different language very, very slowly?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Perl and Type restriction
by ww (Archbishop) on Mar 21, 2010 at 12:29 UTC
      Typed variables can work atop of scalars, so it's not quite the same issue as the linked post. In fact, it's syntactically correct to say
      my Foo $bar;
      It just doesn't do anything.
Re: Perl and Type restriction
by chromatic (Archbishop) on Mar 21, 2010 at 20:49 UTC
    Why Perl 5 don't have compile-time type restriction?

    Because you can't trace all dispatch destinations at compile time. See also "Why are C++ templates so difficult to implement efficiently?"