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.
- Thorsten Altenkirch and Alexander S. Green. 2009. The Quantum IO Monad. Cambridge University Press, 173–205.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Richard Eisenberg, Benoıt Valiron, and Steve Zdancewic. 2012. Typechecking Linear Data: Quantum Computation in Haskell. (2012).Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- The Idris Community. 2017. Uniqueness Types. (2017). http://docs.idris-lang. org/en/latest/reference/uniqueness-types.htmlGoogle Scholar
- 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 Scholar
Digital Library
- P.B. Levy. 2012. Call-By-Push-Value: A Functional/Imperative Synthesis. Springer Netherlands.Google Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- Saunders Mac Lane. 1978. Categories for the working mathematician. Vol. 5. Springer Science & Business Media.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- M.A. Nielsen and I.L. Chuang. 2010. Quantum Computation and Quantum Information: 10th Anniversary Edition. Cambridge University Press. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- François Pottier and Jonathan Protzenko. 2013. Programming with permissions in Mezzo. ACM SIGPLAN Notices 48, 9 (nov 2013), 173–184. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- Neil J. Ross. 2015. Algebraic and Logical Methods in Quantum Computation. Ph.D. Dissertation. Dalhousie University.Google Scholar
- Peter Selinger and Benoît Valiron. 2009. Quantum Lambda Calculus. Cambridge University Press, 135–172.Google Scholar
- 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 Scholar
- Philip Wadler. 2014. Propositions as sessions. Journal of Functional Programming 24 (2014), 384–418. Issue Special Issue 2-3. Google Scholar
Digital Library
Index Terms
The linearity Monad
Recommendations
Linear Haskell: practical linearity in a higher-order polymorphic language
Linear type systems have a long and storied history, but not a clear path forward to integrate with existing languages such as OCaml or Haskell. In this paper, we study a linear type system designed with two crucial properties in mind: backwards-...
The linearity Monad
Haskell 2017: Proceedings of the 10th ACM SIGPLAN International Symposium on HaskellWe 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 ...
Modular Compilers Based on Monad Transformers
ICCL '98: Proceedings of the 1998 International Conference on Computer LanguagesThe monadic style of language specification has the advantages of modularity and extensibility: it is simple to add or change features in an interpreter to reflect modifications in the source language. It has proven difficult to extend the method to ...







Comments