skip to main content
research-article

Extending monads with pattern matching

Authors Info & Claims
Published:22 September 2011Publication History
Skip Abstract Section

Abstract

Sequencing of effectful computations can be neatly captured using monads and elegantly written using do notation. In practice such monads often allow additional ways of composing computations, which have to be written explicitly using combinators.

We identify joinads, an abstract notion of computation that is stronger than monads and captures many such ad-hoc extensions. In particular, joinads are monads with three additional operations: one of type m a -> m b -> m (a, b) captures various forms of parallel composition, one of type m a -> m a -> m a that is inspired by choice and one of type m a -> m (m a) that captures aliasing of computations. Algebraically, the first two operations form a near-semiring with commutative multiplication.

We introduce docase notation that can be viewed as a monadic version of case. Joinad laws imply various syntactic equivalences of programs written using docase that are analogous to equivalences about case. Examples of joinads that benefit from the notation include speculative parallelism, waiting for a combination of user interface events, but also encoding of validation rules using the intersection of parsers.

Skip Supplemental Material Section

Supplemental Material

_talk1.mp4

mp4

64.9 MB

References

  1. Haskell Trac. Bring back monad comprehensions, retrieved 2011. http://hackage.haskell.org/trac/ghc/ticket/4370.Google ScholarGoogle Scholar
  2. Haskell Documentation. Control.Monad, retrieved 201.Google ScholarGoogle Scholar
  3. S. Brookes, S. Geva. Computational comonads and intensional semantics. Technical Report Carnegie Mellon University-CS-91-190, Carnegie Mellon University, 1991.Google ScholarGoogle Scholar
  4. N. C. C. Brown. Communicating Haskell Processes: Composable Explicit Concurrency using Monads. In Communicating Process Architectures 2008, pages 67--83, 2008.Google ScholarGoogle Scholar
  5. K. Claessen. A Poor Man's Concurrency Monad. Journal of Functional Programming, 9:313--323, May 1999. ISSN 0956-7968. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. C. Elliott. Push-Pull Functional Reactive Programming. In Haskell Symposium, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. B. Emir, M. Odersky, and J. Williams. Matching Objects with Patterns. In ECOOP 2007, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. M. Fluet, M. Rainey, J. Reppy, and A. Shaw. Implicitly threaded parallelism in Manticore. Journal of Functional Programming, 20 (Special Issue 5-6):537--576, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. G. Giorgidze, T. Grust, N. Schweinsberg, and J. Weijers Bringing Back Monad Comprehensions. To appear in Haskell'11, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. P. Haller and T. Van Cutsem. Implementing Joins using Extensible Pattern Matching. In Proceedings of the 10th International Conference on Coordination Models and Languages, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. HaskellWiki. MonadPlus reform proposal, retrieved 2011. http://tinyurl.com/monadplus-reform-proposal.Google ScholarGoogle Scholar
  12. P. Hudak, A. Courtney, H. Nilsson, and J. Peterson. Arrows, Robots, and Functional Reactive Programming. In Advanced Functional Programming, volume 2638 of LNCS, pages 1949--1949. 2003.Google ScholarGoogle Scholar
  13. J. Hughes. Generalising Monads to Arrows. Science of Computer Programming, 37:67--111, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. G. Hutton and E. Meijer. Monadic Parsing in Haskell. Journal of Functional Programming, 8(4):437--444, July 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. S. P. Jones, S. Marlow, and R. Newton. A Monad for Deterministic Parallelism, 2011. http://tinyurl.com/monad-par. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. S. P. Jones and P. Wadler. Comprehensive Comprehensions. In Haskell'07, pages 61--72, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. R. B. Kieburtz. Codata and Comonads in Haskell. Unpublished manuscript, 1999.Google ScholarGoogle Scholar
  18. E. A. Kmett. The comonad package, retrieved 2011. http://hackage.haskell.org/package/comonad.Google ScholarGoogle Scholar
  19. D. Leijen and E. Meijer. Parsec: Direct Style Monadic Parser Combinators for the Real World. Technical Report UU-CS-2001-27, Department of Computer Science, Universiteit Utrecht, 2001.Google ScholarGoogle Scholar
  20. H. Liu, E. Cheng, and P. Hudak. Causal Commutative Arrows and Their Optimization. In ICFP'09, pages 35--46, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. S. Marlow, P. Maier, H.-W. Loidl, M. K. Aswad, and P. Trinder. Seq no more: Better Strategies for Parallel Haskell. In Haskell'10. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. C. McBride and R. Paterson. Applicative Programming with Effects. Journal of Functional Programming, 18:1--13, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. D. A. Orchard, M. Bolingbroke, and A. Mycroft. Ypnos: Declarative, Parallel Structured Grid Programming. DAMP '10, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. R. Paterson. A New Notation for Arrows. In Proceedings of ICFP'01, pages 229--240. ACM Press, Sept. 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. T. Petricek. Fun with parallel monad comprehensions, 2011. The Monad.Reader, Issue 18.Google ScholarGoogle Scholar
  26. T. Petricek. Explicit speculative parallelism for Haskell's Par monad, http://tomasp.net/blog/speculative-par-monad.aspx, retrieved 2011.Google ScholarGoogle Scholar
  27. T. Petricek and D. Syme. Joinads: A retargetable control-flow construct for reactive, parallel and concurrent programming. In PADL'11, pages 205--219, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. J. H. Reppy. Concurrent Programming in ML. Cambridge University Press, 2007. ISBN 978-0-521-71472-3. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. E. Scholz. Imperative Streams--A Monadic Combinator Library for Synchronous Programming. In ICFP'98, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. S. D. Swierstra. Combinator Parsing: A Short Tutorial. Technical report, Utrecht University, 2008.Google ScholarGoogle Scholar
  31. D. Syme, G. Neverov, and J. Margetson. Extensible Pattern Matching via a Lightweight Language Extension. ICFP, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. P. W. Trinder, K. Hammond, H.-W. Loidl, and S. L. Peyton Jones. Algorithm + Strategy = Parallelism. Journal of Functional Programming, 8(1):23--60, Jan. 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. M. Tullsen. First-Class Patterns. In PADL 2000, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. T. Uustalu and V. Vene. The essence of dataflow programming. In APLAS, pages 2--18, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. P. Wadler. Views: a way for pattern matching to cohabit with data abstraction. POPL, 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. P. Wadler. Comprehending Monads. In Proceedings of the 1990 ACM conference on LISP and functional programming, pages 61--78, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Extending monads with pattern matching

    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 46, Issue 12
      Haskell '11
      December 2011
      129 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/2096148
      Issue’s Table of Contents
      • cover image ACM Conferences
        Haskell '11: Proceedings of the 4th ACM symposium on Haskell
        September 2011
        136 pages
        ISBN:9781450308601
        DOI:10.1145/2034675

      Copyright © 2011 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 ACM 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: 22 September 2011

      Check for updates

      Qualifiers

      • research-article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader