A lambda-calculus for dynamic binding

Laurent Dami
1998 Theoretical Computer Science  
Dynamic binding is a runtime lookup operation which extracts values corresponding to some "names" from some "environments" (finite, unordered associations of names and values). Many situations related with flexible software assembly involve dynamic binding: first-class modules, mobile code, object-oriented message passing. This paper proposes AN, a compact extension of the i-calculus to model dynamic binding, where variables are labelled by names, and where arguments are passed to functions
more » ... g named channels. The resulting formalism preserves familiar properties of the I-calculus, has a Curry-style-type inference system, and has a formal notion of compatibility for reasoning about extensible environments. It can encode records and record extensions, as well as first-class contexts with context-filling operations, and therefore provides a basic framework for expressing a wide range of name-based coordination mechanisms. An experimental functional language based on iN illustrates the exploitation of dynamic binding in programming language design. or Postscript, late binding of message names to methods in object-oriented languages, communication channels in concurrent systems. More recently, several proposals have been made to use first-class environments as a tool for flexible modularity [ 17,211; furthermore, in the new context of coordination models and languages, most proposals addressing distribution issues include some scheme for dynamic binding: the name server of [22], the flexible records of Ariadne [12], the tuples of named values in Sonia [3] are just a few examples. So in several contexts some form of dynamic binding has been acknowledged as a good mechanism for incremental assembly and coordination of software fragments. When comparing these different implementations of a simple concept, it appears that small variations in the name lookup operation or in the constructs for building environments may generate quite different properties. Hence, formal models developed so far for some of these paradigms, in which the dynamic binding features are implicitly incorporated but merged with other computational aspects, are not adequate to perform comparisons and to study dynamic binding in an abstract, general setting. For example, several object calculi have been designed to study message-passing, but they can hardly be used to express the semantics of LISP. By contrast, a formal model in which dynamic binding is factored out from other computational aspects can throw some light on the relationships between various paradigms. We propose such a model, in the form of a il-calculus in which arguments are passed to functions along named channels _ so it is called ;l-calculus with names, or AN for short. We also show how this model is a natural foundation for introducing dynamic binding in a typeful way into functional programming languages like ML [20] or Haskell [ 161. Clearly, dynamic binding has an associated cost in terms of computing resources (memory to store the environments, time to perform lookup operations), but it also has the very appealing aspect of extensibility, i.e. the possibility to add more functionality to an existing piece of code, without affecting its previous behaviour. This comes from the fact that an environment defining a given set of names can be replaced by a bigger environment, defining more names: all name lookup operations involving the original set of names are still valid, but in addition some new lookup operations become possible. As a result, the modified code is "compatible" with the original code, which is very convenient for software evolution. These notions are central to the spirit of objectoriented programming, and are key factors for its success. Hence, semantic studies of languages with dynamic binding should attempt to capture this compatibility relationship, which is asymmetric, rather than usual equivalence relations between programs. A partial answer comes from the methodologies developed for describing subtyping in typed object calculi: one is based on "partial equivalence relationships" (PERs) [6] , which indicate when two values are equivalent at a given type, and the other is based on coercion functions from subtypes to supertypes [S]. However, these do not directly express the fact, very intuitive to programmers, that for example record {x = 1, y = 2) totally subsumes record {x = I}, i.e. can safely replace it at all types. In order to deal with this notion, we explicitly introduce a notion of runtime error in untyped AN, and then define an operational ordering based on the observation of error generation. By
doi:10.1016/s0304-3975(97)00150-3 fatcat:3x262x3ymvhzjomlc5o6gzo3oa