skip to main content
research-article

Lightweight monadic programming in ML

Published:19 September 2011Publication History
Skip Abstract Section

Abstract

Many useful programming constructions can be expressed as monads. Examples include probabilistic modeling, functional reactive programming, parsing, and information flow tracking, not to mention effectful functionality like state and I/O. In this paper, we present a type-based rewriting algorithm to make programming with arbitrary monads as easy as using ML's built-in support for state and I/O. Developers write programs using monadic values of type m τ as if they were of type τ, and our algorithm inserts the necessary binds, units, and monad-to-monad morphisms so that the program type checks. Our algorithm, based on Jones' qualified types, produces principal types. But principal types are sometimes problematic: the program's semantics could depend on the choice of instantiation when more than one instantiation is valid. In such situations we are able to simplify the types to remove any ambiguity but without adversely affecting typability; thus we can accept strictly more programs. Moreover, we have proved that this simplification is efficient (linear in the number of constraints) and coherent: while our algorithm induces a particular rewriting, all related rewritings will have the same semantics. We have implemented our approach for a core functional language and applied it successfully to simple examples from the domains listed above, which are used as illustrations throughout the paper.

Skip Supplemental Material Section

Supplemental Material

_talk2.mp4

References

  1. M. Abadi, A. Banerjee, N. Heintze, and J. G. Riecke. A core calculus of dependency. In POPL, volume 26, pages 147--160, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Nick Benton and Andrew Kennedy. Monads, effects and transformations. In Electronic Notes in Theoretical Computer Science, 1999.Google ScholarGoogle ScholarCross RefCross Ref
  3. Greg Cooper and Shriram Krishnamurthi. Embedding dynamic dataflow in a call-by-value language. In ESOP, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. K. Crary, A. Kliger, and F. Pfenning. A monadic analysis of information flow security with mutable state. Journal of functional programming, 15(02):249--291, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. L. Damas and R. Milner. Principal type-schemes for functional programs. In POPL, pages 207--212, 1982. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. D. E. Denning. A lattice model of secure information flow. Communications of the ACM, 19(5):236--243, 1976. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. D. Devriese and F. Piessens. Information flow enforcement in monadic libraries. In TLDI, pages 59--72, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Conal Elliott and Paul Hudak. Functional reactive animation. In ICFP, pages 263---273, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. A. Filinski. Representing layered monads. In POPL, pages 175--188, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. A. Filinski. Monads in action. In POPL, pages 483--494, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Andrzej Filinski. Representing monads. In POPL, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. J. A. Goguen and J. Meseguer. Security policy and security models. In Symposium on Security and Privacy, pages 11--20, 1982.Google ScholarGoogle ScholarCross RefCross Ref
  13. Graham Hutton and Erik Meijer. Monadic Parsing in Haskell. JFP, 8(4), 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Mark P. Jones. A theory of qualified types. In ESOP, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Mark P. Jones. Coherence for qualified types. Technical Report YALEU/DCS/RR-989, Yale University, September 1993.Google ScholarGoogle Scholar
  16. Mark P. Jones. Simplifying and Improving Qualified Types. Technical Report YALEU/DCS/RR-1040, Yale University, June 1994.Google ScholarGoogle Scholar
  17. Mark P. Jones and Luc Duponcheel. Composing monads. Technical Report YALEU/DCS/RR-1004, Yale University, 1993.Google ScholarGoogle Scholar
  18. Oleg Kiselyov and Chung chieh Shan. Embedded probabilistic programming. In DSL, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. P. Li and S. Zdancewic. Encoding information flow in Haskell. In CSFW, pages 16--27, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Z. Luo. Coercions in a polymorphic type system. MSCS, 18(4), 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Z. Luo and R. Kießling. Coercions in Hindley-Milner systems. In Proc. of Types, 2004.Google ScholarGoogle Scholar
  22. Eugenio Moggi. Computational lambda-calculus and monads. In LICS, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Judea Pearl. Embracing causality in default reasoning (research note). Artificial Intelligence, 35(2):259---271, 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. F. Pottier and V. Simonet. Information flow inference for ML. TOPLAS, 25(1):117--158, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Norman Ramsey and Avi Pfeffer. Stochastic lambda calculus and monads of probability distributions. In POPL, pages 154--165, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Alejandro Russo, Koen Claessen, and John Hughes. A library for light-weight information-flow security in haskell. In Haskell, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Nikhil Swamy, Nataliya Guts, Daan Leijen, and Michael Hicks. Lightweight monadic programming in ML. Technical Report MSR-TR-2011-039, Microsoft Research, May 2011.Google ScholarGoogle Scholar
  28. Nikhil Swamy, Michael Hicks, and Gavin M. Bierman. A theory of typed coercions and its applications. In ICFP, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Philip Wadler. The essence of functional programming. In POPL, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Lightweight monadic programming in ML

      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 9
        ICFP '11
        September 2011
        456 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/2034574
        Issue’s Table of Contents
        • cover image ACM Conferences
          ICFP '11: Proceedings of the 16th ACM SIGPLAN international conference on Functional programming
          September 2011
          470 pages
          ISBN:9781450308656
          DOI:10.1145/2034773

        Copyright © 2011 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 19 September 2011

        Check for updates

        Qualifiers

        • research-article

      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!