Abstract
This paper is about a Glasgow Haskell Compiler (GHC) extension that generalises Haskell's list comprehension notation to monads. The monad comprehension notation implemented by the extension supports generator and filter clauses, as was the case in the Haskell 1.4 standard. In addition, the extension generalises the recently proposed parallel and SQL-like list comprehension notations to monads. The aforementioned generalisations are formally defined in this paper. The extension will be available in GHC 7.2.
This paper gives several instructive examples that we hope will facilitate wide adoption of the extension by the Haskell community. We also argue why the do notation is not always a good fit for monadic libraries and embedded domain-specific languages, especially for those that are based on collection monads. Should the question of how to integrate the extension into the Haskell standard arise, the paper proposes a solution to the problem that led to the removal of the monad comprehension notation from the language standard.
Supplemental Material
- Database-Supported Haskell. http://hackage.haskell.org/package/DSH.Google Scholar
- Hugs - a functional programming system based on Haskell 98. http://www.haskell.org/hugs/.Google Scholar
- The Glasgow Haskell Compiler. http://www.haskell.org/ghc/.Google Scholar
- Haskell 1.4: A Non-Strict, Purely Functional Language, 1997.Google Scholar
- Guy Blelloch. Scans as Primitive Parallel Operations. IEEE Transactions on Computers, 38(11), 1989. Google Scholar
Digital Library
- Guy Blelloch. NESL: A nested data-parallel language. Technical report, Pittsburgh, PA, USA, 1992. Google Scholar
Digital Library
- Peter Buneman, Leonid Libkin, Dan Suciu, Val Tannen, and Limsoon Wong. Comprehension Syntax. SIGMOD Record, 23:87--96, 1994. Google Scholar
Digital Library
- Rod Burstall and John Darlington. Transformation Systems for Developing Recursive Programs. Journal of the ACM, 24(1):44--67, 1977. Google Scholar
Digital Library
- Manuel M. T. Chakravarty, Roman Leshchinskiy, Simon Peyton Jones, Gabriele Keller, and Simon Marlow. Data Parallel Haskell: A Status Report. In Proceedings of the 2007 Workshop on Declarative Aspects of Multicore Programming, DAMP '07, pages 10--18, Nice, France, 2007. ACM. Google Scholar
Digital Library
- Martin Erwig. Comprehending ADTs. Unpublished draft, http://web.engr.oregonstate.edu/~erwig/adtfold/compr.pdf, 2011.Google Scholar
- Leonidas Fegaras and David Maier. Towards an Effective Calculus for Object Query Languages. In Proceedings of the SIGMOD Conference, San Jose, CA, USA, 1995. ACM. Google Scholar
Digital Library
- George Giorgidze, Torsten Grust, Tom Schreiber, and Jeroen Weijers. Haskell boards the Ferry: Database-supported program execution for Haskell. In Revised selected papers of the 22nd international symposium on Implementation and Application of Functional Languages, Alphen aan den Rijn, Netherlands, volume 6647 of Lecture Notes in Computer Science. Springer, 2010. Peter Landin Prize for the best paper at IFL 2010. Google Scholar
Digital Library
- Torsten Grust. How to Comprehend Queries Functionally. Intelligent Information Systems, 12(2/3):191--218, 1999. Google Scholar
Digital Library
- Torsten Grust. Monad Comprehensions: A Versatile Representation for Queries. In Peter M.D. Gray, Larry Kerschberg, Peter J.H. King, and Alexandra Poulovassilis, editors, The Functional Approach to Data Management. Springer, 2003.Google Scholar
- Paul Hudak, John Hughes, Simon Peyton Jones, and Philip Wadler. A History of Haskell: Being Lazy with Class. In Proceedings of the third ACM SIGPLAN Conference on History of Programming Languages, HOPL III, pages 1--55, San Diego, CA, USA, 2007. ACM. Google Scholar
Digital Library
- Graham Hutton and Erik Meijer. Monadic Parser Combinators. Technical Report NOTTCS-TR-96-4, University of Nottingham, Nottingham, UK, 1996.Google Scholar
- Mark Jones. The Implementation of the Gofer Functional Programming System. Technical Report YALEU/DCS/RR-1030, Yale University, New Haven, CT, USA, 1994.Google Scholar
- Won Kim. On Optimizing an SQL-like Nested Query. Transactions on Database Systems (TODS), 7(3), 1982. Google Scholar
Digital Library
- Jeff Lewis. Cryptol: specification, implementation and verification of high-grade cryptographic applications. In Proceedings of the 2007 ACM workshop on Formal methods in security engineering, FMSE '07, pages 41--41, New York, NY, USA, 2007. ACM. Google Scholar
Digital Library
- Conor McBride and Ross Paterson. Applicative programming with effects. Journal of Functional Programming, 18(01):1--13, 2008. Google Scholar
Digital Library
- Erik Meijer and Brian Beckman. XLinq: XML Programming Refactored (The Return of the Monoids). In Proceedings of the XML Conference, Atlanta, GA, USA, 2005.Google Scholar
- Erik Meijer, Brian Beckman, and Gavin Bierman. LINQ: Reconciling Objects, Relations, and XML in the .NET Framework. In Proceedings of the SIGMOD Conference, Chicago, IL, USA, 2006. ACM. Google Scholar
Digital Library
- Tomas Petricek. Fun with parallel monad comprehensions. The Monad Reader Issue 18, 2011. http://themonadreader.wordpress.com/.Google Scholar
- Simon Peyton Jones, editor. Haskell 98 Language and Libraries -- The Revised Report. Cambridge University Press, Cambridge, England, 2003.Google Scholar
- Simon Peyton Jones and Philip Wadler. Comprehensive Comprehensions. In Proceedings of the ACM SIGPLAN Workshop on Haskell, pages 61--72, Freiburg, Germany, 2007. ACM. Google Scholar
Digital Library
- Phil Trinder. Comprehensions, a Query Notation for DBPLs. In Proceedings of the 3rd International Workshop on Database Programming Languages, DBPL, Nafplion, Greece, 1991. Google Scholar
Digital Library
- David Turner. The Semantic Elegance of Applicative Languages. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture, FPCA. ACM, 1981. Google Scholar
Digital Library
- Philip Wadler. Comprehending Monads. In Proceedings of the 1990 ACM Conference on LISP and Functional Programming, LFP '90, pages 61--78, Nice, France, 1990. ACM. Google Scholar
Digital Library
- Limsoon Wong. Querying Nested Collections. PhD thesis, University of Pennsylvania, Philadelphia, PA, USA, 1994. Google Scholar
Digital Library
- Limsoon Wong. Kleisli, A Functional Query System. Journal of Functional Programming, 10(1):19--56, 2000. Google Scholar
Digital Library
Index Terms
Bringing back monad comprehensions
Recommendations
Bringing back monad comprehensions
Haskell '11: Proceedings of the 4th ACM symposium on HaskellThis paper is about a Glasgow Haskell Compiler (GHC) extension that generalises Haskell's list comprehension notation to monads. The monad comprehension notation implemented by the extension supports generator and filter clauses, as was the case in the ...
Layout-sensitive language extensibility with SugarHaskell
Haskell '12: Proceedings of the 2012 Haskell SymposiumProgrammers need convenient syntax to write elegant and concise programs. Consequently, the Haskell standard provides syntactic sugar for some scenarios (e.g., do notation for monadic code), authors of Haskell compilers provide syntactic sugar for more ...
Layout-sensitive language extensibility with SugarHaskell
Haskell '12Programmers need convenient syntax to write elegant and concise programs. Consequently, the Haskell standard provides syntactic sugar for some scenarios (e.g., do notation for monadic code), authors of Haskell compilers provide syntactic sugar for more ...







Comments