Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Why Perl Is Not My Favourite Functional Programming Language

by FoxtrotUniform (Prior)
on Nov 06, 2004 at 02:50 UTC ( #405684=note: print w/ replies, xml ) Need Help??


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


Comment on Re^2: Why Perl Is Not My Favourite Functional Programming Language
Select or Download Code
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://405684]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2015-07-31 03:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls