skip to main content
10.1145/2951913.2951949acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

All sorts of permutations (functional pearl)

Published:04 September 2016Publication History

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
            • Published in

              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

              Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

              Publisher

              Association for Computing Machinery

              New York, NY, United States

              Publication History

              • Published: 4 September 2016

              Permissions

              Request permissions about this article.

              Request Permissions

              Check for updates

              Qualifiers

              • research-article

              Acceptance Rates

              Overall Acceptance Rate333of1,064submissions,31%

              Upcoming Conference

              ICFP '24

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader