skip to main content
article

The linearity Monad

Published:07 September 2017Publication History
Skip Abstract Section

Abstract

We introduce a technique for programming with domain-specific linear languages using the monad that arises from the theory of linear/non-linear logic. In this work we interpret the linear/non-linear model as a simple, effectful linear language embedded inside an existing non-linear host language. We implement a modular framework for defining these linear EDSLs in Haskell, allowing both shallow and deep embeddings. To demonstrate the effectiveness of the framework and the linearity monad, we implement languages for file handles, mutable arrays, session types, and quantum computing.

References

  1. Thorsten Altenkirch and Alexander S. Green. 2009. The Quantum IO Monad. Cambridge University Press, 173–205.Google ScholarGoogle Scholar
  2. Erik Barendsen and Sjaak Smetsers. 1993. Conventional and uniqueness typing in graph rewrite systems. In Proceedings of the 13th Conference of Foundations of Software Technology and Theoretical Computer Science, Rudrapatna K. Shyamasundar (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 41–51. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Nick Benton. 1995. A mixed linear and non-linear logic: Proofs, terms and models. In Computer Science Logic, Leszek Pacholski and Jerzy Tiuryn (Eds.). Lecture Notes in Computer Science, Vol. 933. Springer Berlin Heidelberg, 121–135. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Nick Benton, Gavin Bierman, Valeria de Paiva, and Martin Hyland. 1993. A term calculus for Intuitionistic Linear Logic. In Typed Lambda Calculi and Applications, Marc Bezem and JanFriso Groote (Eds.). Lecture Notes in Computer Science, Vol. 664. Springer Berlin Heidelberg, 75–90. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Nick Benton and Philip Wadler. 1996. Linear logic, monads and the lambda calculus. In Proceedings of the Eleventh Annual IEEE Symposium on Logic in Computer Science, 1996. LICS ’96. 420–431. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Jean-Philippe Bernardy, Mathieu Boespflug, Ryan R. Newton, Simon Peyton Jones, and Arnaud Spiwack. 2017. Retrofitting Linear Types. (2017). https://www.microsoft.com/en-us/research/wp-content/uploads/2017/ 03/haskell-linear-submitted.pdfGoogle ScholarGoogle Scholar
  7. Luís Caires and Frank Pfenning. 2010. Session Types as Intuitionistic Linear Propositions. In CONCUR 2010 - Concurrency Theory, Paul Gastin and François Laroussinie (Eds.). Lecture Notes in Computer Science, Vol. 6269. Springer Berlin Heidelberg, 222–236. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Chih-Ping Chen and Paul Hudak. 1997. Rolling your own mutable ADT—a connection between linear types and monads. In Proceedings of the 24th ACM SIGPLAN-SIGACT symposium on Principles of programming languages - POPL ’97. Association for Computing Machinery (ACM). Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Richard Eisenberg, Benoıt Valiron, and Steve Zdancewic. 2012. Typechecking Linear Data: Quantum Computation in Haskell. (2012).Google ScholarGoogle Scholar
  10. Richard A. Eisenberg and Jan Stolarek. 2014. Promoting Functions to Type Families in Haskell. In Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell (Haskell ’14). ACM, New York, NY, USA, 95–106. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Richard A. Eisenberg, Stephanie Weirich, and Hamidhasan G. Ahmed. 2016. Visible Type Application. In Programming Languages and Systems: 25th European Symposium on Programming, ESOP 2016, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2016, April 2–8, 2016, Peter Thiemann (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 229–254.Google ScholarGoogle Scholar
  12. Matthew Fluet, Greg Morrisett, and Amal Ahmed. 2006. Linear Regions Are All You Need. In Programming Languages and Systems. Springer Science + Business Media, 7–21. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Alexander S. Green, Peter LeFanu Lumsdaine, Neil J. Ross, Peter Selinger, and Benoît Valiron. 2013. Quipper: A Scalable Quantum Programming Language. In Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’13). ACM, New York, NY, USA, 333–342. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. The Idris Community. 2017. Uniqueness Types. (2017). http://docs.idris-lang. org/en/latest/reference/uniqueness-types.htmlGoogle ScholarGoogle Scholar
  15. Mark P. Jones. 2000. Type Classes with Functional Dependencies. In Programming Languages and Systems: 9th European Symposium on Programming, ESOP 2000, Gert Smolka (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 230–244. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. P.B. Levy. 2012. Call-By-Push-Value: A Functional/Imperative Synthesis. Springer Netherlands.Google ScholarGoogle Scholar
  17. Sam Lindley and J. Garrett Morris. 2015. A Semantics for Propositions as Sessions. In Proceedings of Programming Languages and Systems, 24th European Symposium on Programming, ESOP 2015, Jan Vitek (Ed.), Vol. 9032. Springer Berlin Heidelberg, London, UK, 560–584.Google ScholarGoogle Scholar
  18. Sam Lindley and J. Garrett Morris. 2016. Embedding Session Types in Haskell. In Proceedings of the 9th International Symposium on Haskell (Haskell 2016). ACM, New York, NY, USA, 133–145. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Saunders Mac Lane. 1978. Categories for the working mathematician. Vol. 5. Springer Science & Business Media.Google ScholarGoogle Scholar
  20. Nicholas D. Matsakis and Felix S. Klock, II. 2014. The Rust Language. In Proceedings of the 2014 ACM SIGAda Annual Conference on High Integrity Language Technology (HILT ’14). ACM, New York, NY, USA, 103–104. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Karl Mazurak and Steve Zdancewic. 2010. Lolliproc: To Concurrency from Classical Linear Logic via Curry-Howard and Control. SIGPLAN Not. 45, 9 (Sept 2010), 39–50. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Karl Mazurak, Jianzhou Zhao, and Steve Zdancewic. 2010. Lightweight linear types in system F°. In Proceedings of the 5th ACM SIGPLAN workshop on Types in language design and implementation - TLDI '10. Association for Computing Machinery (ACM). Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Conor McBride. 2016. I Got Plenty o’ Nuttin’. In A List of Successes That Can Change the World: Essays Dedicated to Philip Wadler on the Occasion of His 60th Birthday, Sam Lindley, Conor McBride, Phil Trinder, and Don Sannella (Eds.). Springer International Publishing, 207–233.Google ScholarGoogle Scholar
  24. J. Garrett Morris. 2016. The Best of Both Worlds: Linear Functional Programming Without Compromise. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016). New York, NY, USA, 448–461. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. M.A. Nielsen and I.L. Chuang. 2010. Quantum Computation and Quantum Information: 10th Anniversary Edition. Cambridge University Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. James Noble, Jan Vitek, and John Potter. 1998. Flexible alias protection. In ECOOP’98 — Object-Oriented Programming: 12th European Conference Brussels, Belgium, July 20–24, 1998 Proceedings, Eric Jul (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 158–185. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. E. G. J. M. H. Nöcker, J. E. W. Smetsers, M. C. J. D. van Eekelen, and M. J. Plasmeijer. 1991. Concurrent clean. Springer Berlin Heidelberg, Berlin, Heidelberg, 202–219.Google ScholarGoogle Scholar
  28. Dominic Orchard and Nobuko Yoshida. 2016. Effects As Sessions, Sessions As Effects. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’16). ACM, New York, NY, USA, 568–581. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Jennifer Paykin, Robert Rand, and Steve Zdancewic. 2017. QWIRE: A Core Language for Quantum Circuits. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2017). ACM, New York, NY, USA, 846–858. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Jeff Polakow. 2015. Embedding a full linear Lambda calculus in Haskell. In Proceedings of the 8th ACM SIGPLAN Symposium on Haskell, Haskell 2015, Vancouver, BC, Canada, September 3-4, 2015. 177–188. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. François Pottier and Jonathan Protzenko. 2013. Programming with permissions in Mezzo. ACM SIGPLAN Notices 48, 9 (nov 2013), 173–184. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Riccardo Pucella and Jesse A. Tov. 2008. Haskell Session Types with (Almost) No Class. In Proceedings of the First ACM SIGPLAN Symposium on Haskell (Haskell ’08). ACM, New York, NY, USA, 25–36. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Robert Rand, Jennifer Paykin, and Steve Zdancewic. 2017. QWIRE Practice: Formal Verification of Quantum Verification in Coq. (2017). Quantum Physics and Logic (QPL), July 3–7, 2017, Nijmegen, Amsterdam.Google ScholarGoogle Scholar
  34. Neil J. Ross. 2015. Algebraic and Logical Methods in Quantum Computation. Ph.D. Dissertation. Dalhousie University.Google ScholarGoogle Scholar
  35. Peter Selinger and Benoît Valiron. 2009. Quantum Lambda Calculus. Cambridge University Press, 135–172.Google ScholarGoogle Scholar
  36. Philip Wadler. 1990. Linear types can change the world!. In IFIP TC 2 Working Conference on Programming Concepts and Methods, Sea of Galilee, Israel. North Holland.Google ScholarGoogle Scholar
  37. Philip Wadler. 2014. Propositions as sessions. Journal of Functional Programming 24 (2014), 384–418. Issue Special Issue 2-3. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. The linearity Monad

    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 52, Issue 10
      Haskell '17
      October 2017
      211 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/3156695
      • Editor:
      • Andy Gill
      Issue’s Table of Contents
      • cover image ACM Conferences
        Haskell 2017: Proceedings of the 10th ACM SIGPLAN International Symposium on Haskell
        September 2017
        211 pages
        ISBN:9781450351829
        DOI:10.1145/3122955

      Copyright © 2017 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 7 September 2017

      Check for updates

      Qualifiers

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