skip to main content
article

All sorts of permutations (functional pearl)

Published:04 September 2016Publication History
Skip Abstract Section

Abstract

The combination of non-determinism and sorting is mostly associated with permutation sort, a sorting algorithm that is not very useful for sorting and has an awful running time. In this paper we look at the combination of non-determinism and sorting in a different light: given a sorting function, we apply it to a non-deterministic predicate to gain a function that enumerates permutations of the input list. We get to the bottom of necessary properties of the sorting algorithms and predicates in play as well as discuss variations of the modelled non-determinism. On top of that, we formulate and prove a theorem stating that no matter which sorting function we use, the corresponding permutation function enumerates all permutations of the input list. We use free theorems, which are derived from the type of a function alone, to prove the statement.

References

  1. S. Antoy and M. Hanus. New Functional Logic Design Patterns. WFLP’11, pages 19–34. Springer LNCS 6816, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Nils Anders Danielsson, John Hughes, Patrik Jansson, and Jeremy Gibbons. Fast and Loose Reasoning is Morally Correct. POPL’06, pages 206–217. ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Sebastian Fischer and Jan Christiansen. Curry mailing list, July 2009.Google ScholarGoogle Scholar
  4. Michael Hanus. The Integration of Functions into Logic Programming: From Theory to Practice. Journal of Logic Programming, pages 583– 628, 1994.Google ScholarGoogle ScholarCross RefCross Ref
  5. Selmer M Johnson. Generation of Permutations by Adjacent Transposition. Mathematics of computation, pages 282–285, 1963.Google ScholarGoogle Scholar
  6. Sheng Liang, Paul Hudak, and Mark Jones. Monad Transformers and Modular Interpreters. In Proceedings of the 22nd ACM SIGPLANSIGACT symposium on Principles of programming languages, pages 333–343. ACM, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Colin L Mallows. Patience Sorting. SIAM review, 1963.Google ScholarGoogle Scholar
  8. George Pollard, Sebastian Fischer, Ganesh Sittampalam, and Ryan Ingram. Haskell mailing list, July 2009.Google ScholarGoogle Scholar
  9. H. F. Trotter. Algorithm 115: Perm. Commun. ACM, pages 434–435, 1962. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Twan van Laarhoven et al. Haskell mailing list, December 2007.Google ScholarGoogle Scholar
  11. Philip Wadler. Theorems for Free! FPCA’89, pages 347–359. ACM, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. All sorts of permutations (functional pearl)

            Recommendations

            Comments

            Login options

            Check if you have access through your login credentials or your institution to get full access on this article.

            Sign in

            Full Access

            • Published in

              cover image ACM SIGPLAN Notices
              ACM SIGPLAN Notices  Volume 51, Issue 9
              ICFP '16
              September 2016
              501 pages
              ISSN:0362-1340
              EISSN:1558-1160
              DOI:10.1145/3022670
              Issue’s Table of Contents
              • cover image ACM Conferences
                ICFP 2016: Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming
                September 2016
                501 pages
                ISBN:9781450342193
                DOI:10.1145/2951913

              Copyright © 2016 ACM

              Publisher

              Association for Computing Machinery

              New York, NY, United States

              Publication History

              • Published: 4 September 2016

              Check for updates

              Qualifiers

              • article
            • Article Metrics

              • Downloads (Last 12 months)12
              • Downloads (Last 6 weeks)1

              Other Metrics

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader
            About Cookies On This Site

            We use cookies to ensure that we give you the best experience on our website.

            Learn more

            Got it!