Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Tuesday February 07, 2006
12:53 PM

Type Inference in Perl 5

[ #28612 ]

Devel::TypeCheck is one of those projects I desperately want to see gain some traction, but it hasn't. Part of the reason for this is the following code from B::TypeCheck (which, believe it or not, is formatted for clarity):

# Fully qualified terminal types
our $IO
  = Devel::TypeCheck::Type::Mu->new( Devel::TypeCheck::Type::Io->new() );
our $PV = Devel::TypeCheck::Type::Mu->new(
    Devel::TypeCheck::Type::Kappa->new(
        Devel::TypeCheck::Type::Upsilon->new(
            Devel::TypeCheck::Type::Pv->new()
        )
    )
);
our $IV = Devel::TypeCheck::Type::Mu->new(
    Devel::TypeCheck::Type::Kappa->new(
        Devel::TypeCheck::Type::Upsilon->new(
            Devel::TypeCheck::Type::Nu->new(
                Devel::TypeCheck::Type::Iv->new()
            )
        )
    )
);
our $DV = Devel::TypeCheck::Type::Mu->new(
    Devel::TypeCheck::Type::Kappa->new(
        Devel::TypeCheck::Type::Upsilon->new(
            Devel::TypeCheck::Type::Nu->new(
                Devel::TypeCheck::Type::Dv->new()
            )
        )
    )
);

OK, got that? Just to give you a heads up, Devel::TypeCheck::Type::Kappa, according to the docs, is a type representing a scalar. Using this information and judicious use of the aliased module, we can do this:

use aliased 'Devel::TypeCheck::Type::Kappa', 'Scalar';

Which will allow us to do this:

# Fully qualified terminal types
our $IO = All->new( IO->new() );
our $PV = All->new( Scalar->new( Printable->new( String->new() ) ) );
our $IV = All->new(
    Scalar->new( Printable->new( Number->new( Integer->new() ) ) ) );
our $DV
  = All->new( Scalar->new( Printable->new( Number->new( Double->new() ) ) ) );

Now that's still tough to see exactly where this is going, but it's much more readable. I suspect that if this is the code we saw, some intrepid folks might actually submit patches to get Devel::TypeCheck to work on something other than 5.8.1.

Mind you, type inference really can't work on Perl 5, but we might get an 80% solution. The work is on the CPAN (it was a Summer of Code project) and I'd love to see where this could take us.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.