Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^5: short sorts

by Arunbear (Parson)
on Apr 07, 2012 at 15:37 UTC ( #963922=note: print w/ replies, xml ) Need Help??


in reply to Re^4: short sorts
in thread short sorts

I've been trying to learn Haskell for greater good. It's a functional language, which (among other things) means functions are first class citizens: you can pass them as arguments to other functions, return them from functions, and easily combine them with other functions.

e.g. whereas in Perl you can create a new string with
$foo = $bar . $ram . $ewe;
in Haskell you can create a new function with
f = g . h . i
(assuming all the argument types match up).

That's what the Compose function I wrote does. I thought of doing that after noticing how similar your various sort functions were, and how they could be built by composing/layering basic operations on top of one another.

I'm not suggesting you write your code like that, I wrote it mainly out of curiosity to see what such a functional style would look like in Perl.


Comment on Re^5: short sorts
Select or Download Code
Re^6: short sorts
by Lady_Aleena (Chaplain) on Apr 10, 2012 at 02:02 UTC

    I am very happy that I gave you something with which to experiment. If you think of anything else you want this to do, please let me see! :)

    Have a cookie and a very nice day!
    Lady Aleena
Re^6: short sorts
by topher (Scribe) on Apr 25, 2012 at 22:50 UTC
    If you're really interested in functional style programming in Perl, you should check out Higher Order Perl, by Mark Jason Dominus. The whole book is about applying functional programming techniques and style to Perl. It's a pretty amazing book. It's also available free online. Hard to beat that.
      I've got a copy already. It is very educational, but doesn't have much to say about composing functions (as far as I can tell).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2014-09-30 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (367 votes), past polls