Nothing Special   »   [go: up one dir, main page]

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

Lightweight monadic programming in ML

Published: 19 September 2011 Publication History

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.

Supplementary Material

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

Cited By

View all
  • (2020)Monadification of attribute grammarsProceedings of the 13th ACM SIGPLAN International Conference on Software Language Engineering10.1145/3426425.3426941(175-195)Online publication date: 16-Nov-2020
  • (2020)SteelCore: an extensible concurrent separation logic for effectful dependently typed programsProceedings of the ACM on Programming Languages10.1145/34090034:ICFP(1-30)Online publication date: 3-Aug-2020
  • (2019)Effects Without Monads: Non-determinism – Back to the Meta LanguageElectronic Proceedings in Theoretical Computer Science10.4204/EPTCS.294.2294(15-40)Online publication date: 16-May-2019
  • Show More Cited By

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

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
  • 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
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]

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 19 September 2011

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. coercion
  2. coherence
  3. monad
  4. rewriting
  5. type

Qualifiers

  • Research-article

Conference

ICFP '11
Sponsor:

Acceptance Rates

ICFP '11 Paper Acceptance Rate 33 of 92 submissions, 36%;
Overall Acceptance Rate 333 of 1,064 submissions, 31%

Upcoming Conference

ICFP '25
ACM SIGPLAN International Conference on Functional Programming
October 12 - 18, 2025
Singapore , Singapore

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)4
  • Downloads (Last 6 weeks)1
Reflects downloads up to 20 Nov 2024

Other Metrics

Citations

Cited By

View all
  • (2020)Monadification of attribute grammarsProceedings of the 13th ACM SIGPLAN International Conference on Software Language Engineering10.1145/3426425.3426941(175-195)Online publication date: 16-Nov-2020
  • (2020)SteelCore: an extensible concurrent separation logic for effectful dependently typed programsProceedings of the ACM on Programming Languages10.1145/34090034:ICFP(1-30)Online publication date: 3-Aug-2020
  • (2019)Effects Without Monads: Non-determinism – Back to the Meta LanguageElectronic Proceedings in Theoretical Computer Science10.4204/EPTCS.294.2294(15-40)Online publication date: 16-May-2019
  • (2018)Unsupervised Similarity Learning through Rank Correlation and kNN SetsACM Transactions on Multimedia Computing, Communications, and Applications10.1145/324105314:4(1-23)Online publication date: 23-Oct-2018
  • (2018)Wearable Technology Brings Security to Alexa and SiriGetMobile: Mobile Computing and Communications10.1145/3229316.322932822:1(35-38)Online publication date: 25-May-2018
  • (2018)Backscatter as a Covert Channel in Mobile DevicesGetMobile: Mobile Computing and Communications10.1145/3229316.322932722:1(31-34)Online publication date: 25-May-2018
  • (2018)The Tick Programmable Low-Latency SDR SystemGetMobile: Mobile Computing and Communications10.1145/3229316.322932622:1(26-30)Online publication date: 25-May-2018
  • (2018)Learning to Recommend Related Entities With Serendipity for Web Search UsersACM Transactions on Asian and Low-Resource Language Information Processing10.1145/318566317:3(1-22)Online publication date: 23-Apr-2018
  • (2018)Incorporating Prior Knowledge into Word Embedding for Chinese Word Similarity MeasurementACM Transactions on Asian and Low-Resource Language Information Processing10.1145/318262217:3(1-21)Online publication date: 2-Apr-2018
  • (2018)Application of Structural and Topological Features to Recognize Online Handwritten Bangla CharactersACM Transactions on Asian and Low-Resource Language Information Processing10.1145/317845717:3(1-16)Online publication date: 13-Feb-2018
  • Show More Cited By

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media