Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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.

Replies are listed 'Best First'.
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).
Re^6: short sorts
by Lady_Aleena (Curate) 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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://963922]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2018-01-22 04:56 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (231 votes). Check out past polls.