Compiling With Classical Connectives

The study of polarity in computation has revealed that an "ideal" programming language combines both call-by-value and call-by-name evaluation; the two calling conventions are each ideal for half the types in a programming language. But this binary choice leaves out call-by-need which is used in practice to implement lazy-by-default languages like Haskell. We show how the notion of polarity can be extended beyond the value/name dichotomy to include call-by-need by adding a mechanism for sharing which is enough to compile a Haskell-like functional language with user-defined types. The key to capturing sharing in this mixed-evaluation setting is to generalize the usual notion of polarity "shifts:" rather than just two shifts (between positive and negative) we have a family of four dual shifts. We expand on this idea of logical duality---"and" is dual to "or;" proof is dual to refutation---for the purpose of compiling a variety of types. Based on a general notion of data and codata, we show how classical connectives can be used to encode a wide range of built-in and user-defined types. In contrast with an intuitionistic logic corresponding to pure functional programming, these classical connectives bring more of the pleasant symmetries of classical logic to the computationally-relevant, constructive setting. In particular, an involutive pair of negations bridges the gulf between the wide-spread notions of parametric polymorphism and abstract data types in programming languages. To complete the study of duality in compilation, we also consider the dual to call-by-need evaluation, which shares the computation within the control flow of a program instead of computation within the information flow.

[1]  Chung-Kil Hur,et al.  Pilsner: a compositionally verified compiler for a higher-order imperative language , 2015, ICFP.

[2]  Michel Parigot,et al.  Lambda-Mu-Calculus: An Algorithmic Interpretation of Classical Natural Deduction , 1992, LPAR.

[3]  Simon L. Peyton Jones,et al.  Unboxed Values as First Class Citizens in a Non-Strict Functional Language , 1991, FPCA.

[4]  J. Y. Girard,et al.  Interpretation fonctionelle et elimination des coupures dans l'aritmetique d'ordre superieur , 1972 .

[5]  Andrew W. Appel,et al.  Compiling with Continuations , 1991 .

[6]  John C. Reynolds,et al.  Towards a theory of type structure , 1974, Symposium on Programming.

[7]  Zena M. Ariola,et al.  Beyond Polarity: Towards a Multi-Discipline Intermediate Language with Sharing , 2018, CSL.

[8]  Amr Sabry,et al.  Sequent calculi and abstract machines , 2009, TOPL.

[9]  Jean-Yves Girard,et al.  Linear Logic , 1987, Theor. Comput. Sci..

[10]  Guillaume Munch-Maccagnoni Focalisation and Classical Realisability , 2009, CSL.

[11]  JEAN-MARC ANDREOLI,et al.  Logic Programming with Focusing Proofs in Linear Logic , 1992, J. Log. Comput..

[12]  Paul Downen Sequent Calculus: A Logic and a Language for Computation and Duality , 2017 .

[13]  Matthias Felleisen,et al.  A call-by-need lambda calculus , 1995, POPL '95.

[14]  J. Girard,et al.  Proofs and types , 1989 .

[15]  Hugo Herbelin,et al.  The duality of computation , 2000, ICFP '00.

[16]  Andrew W. Appel,et al.  Compositional CompCert , 2015, POPL.

[17]  Yu Guo,et al.  Deep Specifications and Certified Abstraction Layers , 2015, POPL.

[18]  Noam Zeilberger,et al.  The logical basis of evaluation order and pattern-matching , 2009 .

[19]  Philip Wadler,et al.  Propositions as types , 2015, Commun. ACM.

[20]  Philip Wadler,et al.  Call-by-value is dual to call-by-name , 2003, ACM SIGPLAN International Conference on Functional Programming.

[21]  Zena M. Ariola,et al.  The Duality of Construction , 2014, ESOP.

[22]  G. Gentzen Untersuchungen über das logische Schließen. I , 1935 .

[23]  Zena M. Ariola,et al.  A tutorial on computational classical logic and the sequent calculus , 2018, Journal of Functional Programming.

[24]  Andrew W. Appel,et al.  Verified Compilation for Shared-Memory C , 2014, ESOP.

[25]  Guillaume Munch-Maccagnoni Syntax and Models of a non-Associative Composition of Programs and Proofs. (Syntaxe et modèles d'une composition non-associative des programmes et des preuves) , 2013 .

[26]  Simon L. Peyton Jones,et al.  Compiling without continuations , 2017, PLDI.

[27]  Robert Harper,et al.  Practical Foundations for Programming Languages , 2012 .

[28]  Matthias Felleisen,et al.  On the Expressive Power of Programming Languages , 1990, European Symposium on Programming.

[29]  Simon Peyton-Jones,et al.  Henk: A Typed Intermediate Language , 1997 .

[30]  Tristan Crolard,et al.  Deriving a Hoare-Floyd logic for non-local jumps from a formulae-as-types notion of control , 2011, ArXiv.

[31]  Alan Mycroft,et al.  Extended Call-by-Push-Value: Reasoning About Effectful Programs and Evaluation Order , 2019, ESOP.

[32]  M. Felleisen,et al.  Reasoning about programs in continuation-passing style , 1993 .

[33]  Kathrin Stark,et al.  Call-by-push-value in Coq: operational, equational, and denotational theory , 2019, CPP.

[34]  Noam Zeilberger On the unity of duality , 2008, Ann. Pure Appl. Log..

[35]  Amal Ahmed,et al.  Verifying an Open Compiler Using Multi-language Semantics , 2014, ESOP.

[36]  Daniele Varacca,et al.  Continuations, Processes, and Sharing , 2014, PPDP '14.

[37]  Eugenio Moggi,et al.  Computational lambda-calculus and monads , 1989, [1989] Proceedings. Fourth Annual Symposium on Logic in Computer Science.

[38]  Alexis Saurin,et al.  Classical Call-by-Need and Duality , 2011, TLCA.

[39]  Benjamin C. Pierce,et al.  Types and programming languages: the next generation , 2003, 18th Annual IEEE Symposium of Logic in Computer Science, 2003. Proceedings..

[40]  Guillaume Munch-Maccagnoni,et al.  Formulae-as-types for an involutive negation , 2014, CSL-LICS.

[41]  Simon L. Peyton Jones,et al.  Sequent calculus as a compiler intermediate language , 2016, ICFP.

[42]  Amal Ahmed,et al.  The next 700 compiler correctness theorems (functional pearl) , 2019, Proc. ACM Program. Lang..

[43]  Zhong Shao,et al.  An abstract stack based approach to verified compositional compilation to machine code , 2019, Proc. ACM Program. Lang..

[44]  Zena M. Ariola,et al.  Compositional semantics for composable continuations: from abortive to delimited control , 2014, ICFP.

[45]  Simon Peyton Jones,et al.  Henk: a typed intermediate language , 1997 .

[46]  Tatsuya Hagino,et al.  A Typed Lambda Calculus with Categorical Type Constructors , 1987, Category Theory and Computer Science.

[47]  Timothy G. Griffin,et al.  A formulae-as-type notion of control , 1989, POPL '90.