Skip to main content

A Duality of Sorts

  • Chapter
The Beauty of Functional Code

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 8106))

Abstract

Sorting algorithms are one of the key pedagogical foundations of computer science, and their properties have been studied heavily. Perhaps less well known, however, is the fact that many of the basic sorting algorithms exist as a pair, and that these pairs arise naturally out of the duality between folds and unfolds. In this paper, we make this duality explicit, by showing how to define common sorting algorithms as folds of unfolds, or, dually, as unfolds of folds. This duality is preserved even when considering optimised sorting algorithms that require more exotic variations of folds and unfolds, and intermediary data structures. While all this material arises naturally from a categorical modelling of these recursion schemes, we endeavour to keep this presentation accessible to those not versed in abstract nonsense.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 49.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  • Braun, W., Rem, M.: A logarithmic implementation of flexible arrays. Memorandum MR83/4, Eindhoven University of Technology (1983)

    Google Scholar 

  • Gibbons, J., Jones, G.: The Under-Appreciated Unfold. In: Proceedings of the International Conference on Functional Programming, ICFP 1998, pp. 273–279. ACM (1998), doi:10.1145/289423.289455

    Google Scholar 

  • van Groningen, J., van Noort, T., Achten, P., Koopman, P., Plasmeijer, R.: Exchanging sources between Clean and Haskell: A double-edged front end for the Clean compiler. In: Proceedings of the Third ACM Haskell Symposium on Haskell, Haskell 2010, pp. 49–60. ACM (2010), doi:10.1145/1863523.1863530

    Google Scholar 

  • Hinze, R.: Generic programming with adjunctions. In: Gibbons, J. (ed.) Generic and Indexed Programming. LNCS, vol. 7470, pp. 47–129. Springer, Heidelberg (2012)

    Chapter  Google Scholar 

  • Hinze, R., James, D.W.H., Harper, T., Wu, N., Magalhães, J.P.: Sorting with bialgebras and distributive laws. In: Proceedings of the 8th ACM SIGPLAN Workshop on Generic Programming, WGP 2012, pp. 69–80. ACM (2012), doi:10.1145/2364394.2364405

    Google Scholar 

  • Knuth, D.E.: The Art of Computer Programming, 2nd edn. Sorting and Searching, vol. 3. Addison-Wesley (1998)

    Google Scholar 

  • Meertens, L.: Paramorphisms. Formal Aspects of Computing 4(5), 413–424 (1992), doi:10.1007/BF01211391

    Article  MATH  Google Scholar 

  • Meijer, E., Fokkinga, M., Paterson, R.: Functional programming with bananas, lenses, envelopes and barbed wire. In: Hughes, J. (ed.) FPCA 1991. LNCS, vol. 523, pp. 124–144. Springer, Heidelberg (1991)

    Chapter  Google Scholar 

  • Peyton Jones, S., et al.: Haskell 98, Language and Libraries. The Revised Report. Cambridge University Press (2003), A special issue of JFP

    Google Scholar 

  • Sheard, T., Pasalic, T.: Two-level types and parameterized modules. Journal of Functional Programming 14(5), 547–587 (2004)

    Article  MATH  Google Scholar 

  • Vene, V., Uustalu, T.: Functional programming with apomorphisms (corecursion). Proceedings of the Estonian Academy of Sciences: Physics, Mathematics 47(3), 147–161 (1998)

    MathSciNet  MATH  Google Scholar 

  • Wadler, P.: Deforestation: Transforming programs to eliminate trees. In: Ganzinger, H. (ed.) ESOP 1988. LNCS, vol. 300, pp. 344–358. Springer, Heidelberg (1988)

    Chapter  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2013 Springer-Verlag Berlin Heidelberg

About this chapter

Cite this chapter

Hinze, R., Magalhães, J.P., Wu, N. (2013). A Duality of Sorts. In: Achten, P., Koopman, P. (eds) The Beauty of Functional Code. Lecture Notes in Computer Science, vol 8106. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-40355-2_11

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-40355-2_11

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-40354-5

  • Online ISBN: 978-3-642-40355-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics