From dynamic binding to state via modal possibility

In this paper we propose a typed, purely functional calculus for state (with second-class locations) in which types reflect the dichotomy between reading from and writing into the global store. This is in contrast to the usual formulation of state via monads, where the primitives for reading and writing introduce the same monadic type constructor. We hope to argue that making this distinction is useful, simple, and has strong logical foundations.Our type system is based on the proof-term calculus for constructive modal logic S4, which has two modal type operators: ␣ for necessity and ◊ for possibility. We extend this calculus with the notion of names (which stand for locations) and generalize to indexed families of modal operators (indexed by sets of names). Then, the modal type ␣CA classifies computations of type A which read from store locations listed in the set C. The dual type ␣CA classifies computations which first write into the locations from $C$ and than use the changed store to obtain a value of type A.There are several benefits to this development. First, the necessitation fragment of the language is interesting in its own: it formulates a calculus of dynamic binding. Second, the possibility operator ◊ is a monad, thus forcing the single-threading of memory writes, but not of memory reads (as these are associated with ␣). Finally, the different status of reads and writes gives rise to a natural way of expressing the allocation of uninitialized memory while also providing guarantees that only initialized locations are dereferenced.

[1]  Andrew M. Pitts,et al.  A Metalanguage for Programming with Bound Names Modulo Renaming , 2000, MPC.

[2]  Aleksandar Nanevski Meta-programming with names and necessity , 2002, ICFP '02.

[3]  Lars Birkedal,et al.  A constraint-based region inference algorithm , 2001, Theor. Comput. Sci..

[4]  Peter Lee,et al.  Optimizing ML with run-time code generation , 1996, PLDI '96.

[5]  Frank Pfenning,et al.  Intensionality, extensionality, and proof irrelevance in modal type theory , 2001, Proceedings 16th Annual IEEE Symposium on Logic in Computer Science.

[6]  Philip Wadler,et al.  The essence of functional programming , 1992, POPL '92.

[7]  John Lamping A unified system of parameterization for programming languages , 1988, LFP '88.

[8]  Simon L. Peyton Jones,et al.  State in Haskell , 1995, LISP Symb. Comput..

[9]  Philip Wadler,et al.  The marriage of effects and monads , 1998, ICFP '98.

[10]  John Hughes Global variables in Haskell , 2004, J. Funct. Program..

[11]  Andrew M. Pitts,et al.  Nominal Logic: A First Order Theory of Names and Binding , 2001, TACS.

[12]  Matthias Felleisen,et al.  A Syntactic Approach to Type Soundness , 1994, Inf. Comput..

[13]  Frank Pfenning,et al.  A modal analysis of staged computation , 1996, POPL '96.

[14]  Richard B. Kieburtz Taming effects with monadic typing , 1998, ICFP '98.

[15]  Luc Moreau,et al.  A Syntactic Theory of Dynamic Binding , 1997, High. Order Symb. Comput..

[16]  Frank Pfenning,et al.  A judgmental reconstruction of modal logic , 2001, Mathematical Structures in Computer Science.

[17]  Eugenio Moggi,et al.  Notions of Computation and Monads , 1991, Inf. Comput..

[18]  Lars Birkedal,et al.  From region inference to von Neumann machines via region representation inference , 1996, POPL '96.

[19]  Peter Lee,et al.  Modal types as staging specifications for run-time code generation , 1998, CSUR.

[20]  Satoshi Kobayashi,et al.  Monad as Modality , 1997, Theor. Comput. Sci..

[21]  Laurent Dami,et al.  A Lambda-Calculus for Dynamic Binding , 1998, Theor. Comput. Sci..

[22]  Aleksandar Nanevski A modal calculus for effect handling , 2003 .

[23]  John Launchbury,et al.  Implicit parameters: dynamic scoping with static types , 2000, POPL '00.

[24]  Pierre Jouvelot,et al.  Polymorphic type, region and effect inference , 1992, Journal of Functional Programming.

[25]  Peter Lee,et al.  Run-time code generation and modal-ML , 1998, PLDI.

[26]  Mads Tofte,et al.  Region-based Memory Management , 1997, Inf. Comput..

[27]  Andrew M. Pitts,et al.  A New Approach to Abstract Syntax with Variable Binding , 2002, Formal Aspects of Computing.

[28]  Laurent Dami,et al.  Functional Programming with Dynamic Binding , 1996 .

[29]  Mads Tofte,et al.  Implementation of the typed call-by-value λ-calculus using a stack of regions , 1994, POPL '94.

[30]  Philip Wadler,et al.  Monads for functional programming , 1995, NATO ASI PDC.

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