(unless you tie the filehandle but please don't go there).

Why not?

Frameworks in functional languages like lisp and Haskell do this too because it's easy to do for them as currying is built in and is the "natural" way to do this for their programmers.

I agree (partially), but tieing is a "natural" way in Perl.

Lisp and Haskell have to use currying, because FP languages eshew the concept of variables and state. So much so, that they had to invent "functions that you can only run once" (fancifully named 'monads') in order to get around the inconvenient reality that you cannot represent the real world as mathematical functions who's return values are always defined in terms of their inputs.

Files don't work that way; neither do databases or network connections or users. Perl very much lives in the real world. As LW put it "good chemistry is complicated, and a little bit messy". Perl has constructs for dealing with the real world very efficiently.

It just strikes me that trying to force-fit the FP function passing style on top of Perl is a kind square peg in a round hole thing.

Don't get me wrong. I'm really glad that Tom is posting this Haskell inspired stuff. It's helping me in my attempt to get to grips with Haskell. And I wouldn't try and stop anyone else from using it if they see what I don't. I'm just having a hard time trying to envisage the time when I would want to use currying in a Perl program.

All the examples I find of currying show (the equivalent of) things like

my $double = sub{ mult( 2, @_ ) }; my $doubled = $double->( 3 ); print $doubled; ## ouputs '6'

To which my reaction is "Whoo-pee?". And what's wring with print 2 * 3; ?

Tom at least came up with a vaguely plausible use for it, despite that I can't actually think of any time (with the possible exception of Tk; which I have issues with anyway:) that I might hav eused up till now.

Maybe the penny will drop for me one day soon. Or maybe I'll just have to confine myself to the backwater of inherently procedural thinkers--although I make full use of map, grep, List::Util::reduce et al. as well as having a growing collection of similarly FP-like functions of my own devizing.

So I have picked up on some of the concepts and grasped them with both hands. It's just finding a real-world "killer application" for some of the others, like currying, that leave me cold so far.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail        "Time is a poor substitute for thought"--theorbtwo
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

In reply to Re^5: Near-free function currying in Perl by BrowserUk
in thread Near-free function currying in Perl by tmoertel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.