At the risk of beating the head of a dead horse, and then recursively beating the rest of it, as it sprouts new heads from its tail, I began to think about how a functional programmer would implement shuffle, and no clear solution came to mind. I found a paper that had a binary-tree-based offering (look for "Efficient implementation" in it) that I, as a Haskell illiterate, could make little sense of.

So in the spirit of some of the challenges of late, I challenge our functional programming mavens to offer a Perl functional programming shuffle on a lazy list. You can translate from the Haskell in the paper or present your own solution. The emphasis should be on clarity and elegance (as it always is in functional programming); ideal efficiency appears to be O(N log N) due to lazy lists having no O(1) indexing. O(N^2) is acceptable, I reckon.


Caution: Contents may have been coded under pressure.

In reply to Functional shuffle by Roy Johnson

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, details, 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, summary, 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.