NAME
Sub::Curried - Currying of subroutines via a new 'curry' declarator
SYNOPSIS
curry add_n_to ($n, $val) {
return $n+$val;
}
my $add_10_to = add_n_to( 10 );
say $add_n_to->(4); # 14
# but you can also
say add_n_to(10,4); # also 14
# or more traditionally
say add_n_to(10)->(4);
DESCRIPTION
Currying and Partial Application come from the heady world of functional programming, but are actually useful techniques. Partial Application is used to progressively specialise a subroutine, by pre-binding some of the arguments.
Partial application is the generic term, that also encompasses the concept of plugging in "holes" in arguments at arbitrary positions. Currying is (I think) more specifically the application of arguments progressively from left to right until you have enough of them.
BUGS
No major bugs currently open. Please report any bugs via RT or email, or ping me on IRC (osfameron on irc.perl.org and freenode)
SEE ALSO
Devel::Declare provides the magic (yes, there's a teeny bit of code generation involved, but it's not a global filter, rather a localised parsing hack).
There are several modules on CPAN that already do currying or partial evaluation:
Perl6::Currying - Filter based module prototyping the Perl 6 system
Sub::Curry - seems rather complex, with concepts like blackholes and antispices. Odd.
AutoCurry - creates a currying variant of all existing subs automatically. Very odd.
Sub::DeferredPartial - partial evaluation with named arguments (as hash keys). Has some great debugging hooks (the function is a blessed object which displays what the current bound keys are).
Attribute::Curried - exactly what we want minus the sugar. (The attribute has to declare how many arguments it's expecting)
AUTHOR and LICENSE
(c)2008 osfameron@cpan.org
This module is distributed under the same terms and conditions as Perl itself.
Please submit bugs to RT or shout at me on IRC (osfameron on #london.pm on irc.perl.org)