http://qs321.pair.com?node_id=405684


in reply to Re: Why Perl Is Not My Favourite Functional Programming Language
in thread A mini-language for sequences (part 1)

Have you tried prototypes?

Briefly. I don't fully grok the try/catch example in perldoc perlsub, so I may be missing something, but my failed attempts look like:

#! /usr/bin/perl use strict; use warnings; sub curry(&@) { my ($fn, @args) = @_; return sub { $fn->(@args, @_); } } &curry(+, 2)->();
which of course does not compile. (There's also the issue that in order to really do higher-order functions with prototypes, I'd need to somehow examine fn's prototype and preserve it in the returned sub.)

I'm thinking that a source filter might help, turning builtins used as values into anonymous subs, but I don't know very much about source filters — I'm not even sure that they do what I think they do.

--
Yours in pedantry,
F o x t r o t U n i f o r m

"Anything you put in comments is not tested and easily goes out of date." -- tye

Replies are listed 'Best First'.
Re^3: Why Perl Is Not My Favourite Functional Programming Language
by itub (Priest) on Nov 06, 2004 at 03:46 UTC
    Perhaps I misunderstood what you wanted. While you are certainly in trouble if you want to curry the + operator, I see no problem with a function such as sum.

    use strict; use warnings; use List::Util qw(sum); sub curry(&@) { my ($fn, @args) = @_; return sub { $fn->(@args, @_); } } my $f = curry { sum(@_) } 5; print $f->(3); # prints 8 (5 + 3)
Re^3: Why Perl Is Not My Favourite Functional Programming Language
by brian_d_foy (Abbot) on Nov 19, 2004 at 17:56 UTC