# Patent

## Title
Program operators for composing abstractions

## Abstract

Programming abstractions with at least one expression are composed to a single abstraction using a composition operator. Expressions from the abstractions are unfolded by removing the prefix of each abstraction and substituting formal parameter names in each expression with a common parameter name to define open variables. The unfolded expressions are transformed to a reduced expression using a composition pattern that tunes semantics of the composition operators. The reduced expression is nested in the single abstraction by: appending a selected prefix of the composed abstraction to the reduced expression, binding the open variables of the reduced expression to the formal parameter of the selected prefix, and computing the type of the formal parameter of the selected prefix.

## Background
CROSS-REFERENCE TO RELATED APPLICATIONS
Cross-reference is made to U.S. patent application Ser. No. 10/046,314, entitled “Symmetrical Structural Pattern Matching”, (now published as US 2003/0191847 A1), Ser. No. 10/046,191 entitled “Bi-Valuation Of Programming Statements”, (now published as US 2003/0188297 A1), which are assigned to the same assignee as the present invention and incorporated herein by reference. Cross-reference is also made to concurrently filed U.S. patent application Ser. No. 10/248,287 entitled “Program Compiler With Abstraction Composer”, (now published as US 2004/0148592 A1), which is assigned to the same assignee as the present invention and incorporated herein by reference.
BACKGROUND OF INVENTION 
The present invention relates generally to software programming languages, and more particularly, to a programming language with operators adapted to compose programming abstractions.
Central to all programming languages is the concept of “programming abstractions”. Programming abstractions as used herein describe functional behavior in computer programs through, for example, functions, procedures, or methods. Programming abstractions have the qualities of software code embedding, factorization, and reuse.
Code embedding refers to the use of programming abstractions (also referred to herein as “abstractions”) as building blocks, where abstractions are able to call each other. Code factorization refers to the avoidance of code duplication associated with abstractions in a program. Code reuse refers to the avoidance of duplicating abstractions to develop additional functionality.
More specifically, code factorization avoids the duplication of “n” similar code segments if they are needed at “n” different locations in a software program. These different segments can be transformed into a common abstraction which can be invoked “n” times at a single location in the software program. This operation is called an abstraction because some of the programming instructions are changed in order to operate on variables instead of values. These variables constitute the execution environment of the abstraction, where the value of the variables is specified at runtime.
For example, the operation “10+1” can be abstracted into an abstraction called a λ-abstraction (i.e., lambda-abstraction) that has the form “λ x:int.x+1”, where 10 is now defined as the variable “x” of type integer (i.e., “int”). In effect, the lambda-abstraction has generalized the operation “10+1” making it applicable to any integer, instead of a constant (e.g., 10).
Consequently if this lambda-abstraction is called “F”, then F (10) will compute 11 and F (11) or F (F(10)) will compute 12.
It is therefore advantageous to define computer programs using abstractions to simplify software design by breaking down a complex monolithic program into smaller sub-programs. In addition, programming using abstractions has the additional benefit of simplifying quality assurance testing. For instance, testing a plurality of small sub-programs is easier than testing a large monolithic program because the context of each sub-program is more explicit and the branching complexity is simplified.
Besides code factorization, abstractions enable code reuse. That is, previously created abstractions can be reused when new software is developed by programmers. The reuse of abstractions may be as simple as copying abstractions from a repository of abstractions or from an existing program. In addition, the reuse of abstractions may involve the use of function previously created to create new function.
The creation of a new abstraction that combines the function of two or more existing abstractions is defined herein as the “composition of programming abstractions”. Current software programming techniques are poorly adapted to facilitate the composition of abstractions in a structured and a formal manner; indeed, existing techniques achieve reuse through two basic techniques that simply reuse existing approaches for composing operators that work either by duplicating code defining abstractions or by directly calling abstractions (e.g., by nesting calls). These current techniques for composing abstractions results in the production of unnecessary code at compile time.
For example, assume an existing ∇-abstraction (i.e., nabla-abstraction) “P” that takes any integer “x” and computes its double as output “y” is defined as “P=∇x:int, y:int.(y:=2*x)”. Existing techniques for creating a new abstraction “PP” that encapsulates two subsequent calls to the abstraction “P” would be defined as “PP=∇x:int, y:int.(y:=P(P(x))”. Execution of the composed abstraction PP(3) would produce 12. However this method for composing abstractions could be more efficient because P(P(x)) requires more instructions than necessary to carry out the operation.
Accordingly, it would be desirable to provide a programming language and compiler adapted to compose programming abstractions. Such a programming language and compiler would advantageously speed and simplify program development and maintenance by facilitating the combination of existing abstractions in a structured and formal manner.
SUMMARY OF INVENTION 
In accordance with the invention, there is provided program operators, and a compiler therefor, for composing programming abstractions. Advantageously, the program operators for composing abstractions provide a definitional framework that shows that abstractions are reused and the manner in which they are reused, simplifying program maintenance through increased legibility. In addition, the compilation of the composition of abstractions using the program operators produces a composed abstraction after compilation that is functionally equivalent to existing approaches for composing operators but computationally different, thereby increasing program efficiency at runtime.
For example, composing the existing delta-abstraction “P” (defined above) using a composition operator “pipe” (described in detail below) results in source code that defines a new abstraction as “PP′=P pipe P”. This definition explicitly shows the reuse of programming abstractions in the source code. In addition after compilation, the abstraction PP′ reduces to “PP′=∇ x:int , y: int .( var a=0.a:=2*x; y:=2*a)” which is functionally equivalent yet computationally more efficient than the abstraction PP (defined above).
In accordance with one aspect of the invention, there is provided a method, apparatus and article manufacture therefor, for composing programming abstractions. A composition operation is defined for composing a first abstraction and a second abstraction with a selected composition operator. Each abstraction has a form, a prefix, and at least one expression. The expressions from the first and the second-abstractions are unfolded by: removing the prefix of each abstraction, and substituting formal parameter names in each expression with a common parameter name to define open variables. The unfolded expressions are transformed to a reduced expression using a composition pattern that tunes semantics of the selected composition operator. A prefix is selected that depends on the selected composition operator and the form of the first abstraction and the second abstraction. The selected prefix has a formal parameter with a type. The reduced expression is nested in a third abstraction that composes the first abstraction and the second abstraction by: appending the selected prefix to the reduced expression, binding the open variables of the reduced expression to the formal parameter of the selected prefix; and computing the type of the formal parameter of the selected prefix.



BRIEF DESCRIPTION OF DRAWINGS 
These and other aspects of the invention will become apparent from the following description read in conjunction with the accompanying drawings wherein the same reference numerals have been applied to like parts and in which:
FIG. 1 illustrates a general purpose computer for carrying out the present invention;
FIG. 2 illustrates a detail view of the multi-stage compiler shown in FIG. 1;
FIG. 3 illustrates a logical outline of a method for performing an abstraction composition operation shown in FIG. 2;
FIG. 4 is a flow diagram of the acts performed in the logic outline shown in FIG. 3 for carrying out the composition of abstractions;
FIG. 5 illustrates a binary tree syntactically and illustratively for encoding the arithmetic expression “a=b+10*c”;
FIGS. 6 and 7 illustrate resulting binary trees syntactically and illustratively when two different transformers are applied to the binary tree shown in FIG. 5; and
FIG. 8 illustrates the resulting binary tree syntactically and illustratively when the composition of two transformers is applied to the binary tree shown in FIG. 5.



DETAILED DESCRIPTION 
Outline of Detailed Description
A. Operating Environment
A.1 Multi-Stage Compiler
A.2 Method For Composing Operators
A.3 Detailed Example
B. General Syntax and Operational Semantics
C. Type System
C.1 Defining Sub-Type Relations
C.2 Typing Rules For Defining Well Typed Properties of Terms
D. The Composition of Functional Abstractions
D.1 Typing Of Composition Operators
D.2 Computational Equivalence
D.3 Application To The Computation Of Numerical Series
D.4 Handling Subtype Polymorphism (Generalization)
E. Extending the Calculus with Imperative Expressions
E.1 Computing Environment
E.2 Syntactic Expressions
E.3 Operational Semantics
E.4 Type System
F. Polymorphic Composition of Nabla-Abstractions
F.1 Semantics
F.2 Typing
G. A Set of Composition Operators
H. Safety Properties Of The Calculus
H.1 General Type Preservation Property
H.2 Strong Type Soundness Of The Core Calculus
H.3 Weak Type Soundness Of The Whole Calculus C/F(E)
I. Polymorphic Composition of Records
I.1 Definition
I.2 Using Record Polymorphism In Pam Composition
J. Illustration of a Modeling Tree Transformer
K. Miscellaneous
A. Operating Environment
FIG. 1 illustrates a general purpose computer 110 for carrying out the present invention. The general purpose computer 110 includes hardware 112 and software 114. The hardware 112 is made up of a processor (i.e., CPU) 116, memory 118 (ROM, RAM, etc.), persistent storage 120 (e.g., CD-ROM, hard drive, floppy drive, tape drive, etc.), user I/O 122, and network I/O 124. The user I/O 122 can include a keyboard 126, a pointing device 128 (e.g., pointing stick, mouse, etc.), and the display 130. The network I/O 124 may for example be coupled to a network 132 such as the Internet.
The software 114 of the general purpose computer 110 includes an operating system 136, a source code editor (and debugger) 138, and a multi-stage compiler 140. The operating system 136 permits processor 116 to allow a user of the general purpose computer 110 to compose source code using the source code editor 138. The source code, which is stored in either memory 118 or persistent storage 120, is compiled by the multi-stage compile 140.
A.1 Multi-Stage Compiler
FIG. 2 illustrates a detail view of the multi-stage compiler shown in FIG. 1. The multi-stage compiler includes a tokenizer 206, a parser 208, an importer 210, a type checker 212, a composer 214, a partial evaluator 215, an intermediate format generator 216 that generates intermediate code 220, a code optimizer, and a code generator 218 that generates executable code 204, the details of which are described below.
The multi-stage compiler 140 takes as input source code 202 and produces as output executable code 204. The multi-stage compiler may either operate statically (i.e., during a composition or analysis stage of language processing) or dynamically (i.e., during execution of the executable code). The code generator 218 may produce: executable code that constitutes machine specific operating instructions (i.e., op-codes), byte-codes that may be executed on an interpreter, or a combination of op-codes or byte-codes.
In accordance with the invention, the source code 202 is formulated with at least one abstraction composition operation 222 using for example the source code editor 138, which may be any conventional text editing program. In general, the abstraction composition operation that is defined in the source code 202 composes at least a first abstraction 224 and a second abstraction 226 using a composition operator 228.
During compilation of the source code 202, the composer 214 in the multi-stage compiler 140 reduces the abstraction composition operation 222 to a new abstraction 230. The composed abstraction 230 is later compiled into an executable form by the other elements of the multi-stage compiler 140 as described in more detail below.
In operation, the multi-stage compiler 140 receives as input source code 202 that is formulated with at least one instruction composing two abstractions (e.g., as shown at 222). Recognition of the contents of the source code is broken into two stages. Initially, the tokenizer 206 segments the source code into a sequence of tagged segments. The tagged segments are used by the parser 208, which is concerned with the structure of the source code, to build a concrete tree. The resulting concrete tree is in computable form and contains all of the useful information forming part of the source code that is necessary to formulate executable or intermediate code.
After tokenizing and parsing at 206 and 208, elements referred to in the source code that are external to the source code are resolved by the importer 210 by accessing the intermediate code 220. Subsequently, the type checker 212 applies a type checking process to the concrete tree. The type checking process traverses an abstract representation (i.e., an abstract tree) of the concrete tree, possibly in multiple passes, and decorates the abstract tree with types that add information related to the type of expressions on the abstract tree using the parsing and tokenizing information to define a decorated tree. In addition, the type checker 212 determines whether an expression is “well typed”, using known methods for type checking that allows finding, legitimizing, and propagating types.
The type checker 212 delegates the processing of abstraction composition operations (e.g., abstraction composition operation 222) that are on the decorated tree to the composer 214. Thus, when the type checker 212 detects that some expressions in the source code are defined through composition operators, the type checker 212 passes the decorated tree for processing by the composer 214. The composer 214 reduces the abstraction composition operation 222 on the decorated tree into a new composed abstraction 230 that is decorated with types.
The new expressions and types added to the decorated tree by the composer 214 are then evaluated by the type checker 212 to determine whether those new expressions are well typed. In accordance with the invention, the composition of two abstractions may take place if the resulting composition is well typed. The type system described herein defines a framework for determining whether a composed expression is well typed as defined below. Generally, a well-typed expression satisfies a weak type soundness property, which provides that each transition step preserves typing.
The type checker 212 has the ability to accept subtypes and uses the type system defined below to distinguish the typing of abstractions. For example, the type system distinguishes between non-recursive and recursive abstractions. The advantage of distinguishing between these two types of abstractions is that it increases the precision of the type checking system, thereby allowing the type checker 212 to assert that the composed abstraction 230 is the correct composition of the abstraction composition operation 222.
Once all composition operations have been processed and determined to be well typed, the type checker 212 passes the decorated tree to the partial evaluator 215 which pre-evaluates language instructions in the decorated tree to reduce their complexity. The decorated tree is then evaluated by the intermediate format generator 216 to generate intermediate code 220 (i.e., a linear form of the decorated tree) for later importation by other programs. In addition, the decorated tree is evaluated by the code optimizer 217, which further evaluates the language instructions in the decorated tree to optimize certain aspects (e.g., new syntactic figures that may issue from the composition operation). Advantageously, the optimization performed by the code optimizer 217 takes place after composition by the composer 214, thereby further optimizing any composed abstractions it generates. The decorated tree is then input to the code generator 218 to generate executable code 204 (i.e., object code) for execution, for example, by processor 116 of the general purpose computer 110.
It will be appreciated by those skilled in the art that functional languages (e.g., ML family), which do not use explicit typing, may use the composition operators described herein without having to specify type operations. In an alternate embodiment of the multistage compiler 140, the type of expressions is deduced entirely from the expressions themselves using a modified type checker that guesses (i.e., infers) the best types. In this alternate embodiment, the multi-stage compiler 140 accommodates such functional languages by having the modified type checker reevaluate the decorated tree after being processed by the composer 214 to re-infer types.
A.2 Method for Composing Operators
FIG. 3 illustrates a logical outline of a method for performing the abstraction composition operation 222 shown in FIG. 2 that is performed by the composer 214. FIG. 4 is a flow diagram of the acts performed in the logic outline shown in FIG. 3 for carrying out the composition of a plurality of abstractions. FIGS. 3 and 4 are referred to simultaneously below.
Initially at 402 in FIG. 4, a composition operation that composes a plurality of abstractions with a composition operator is defined as shown in FIGS. 2 and 3 at 222. It will be appreciate that the composition operation 222 could include two or more abstractions that are composed according to one or more composition operators.
Composition operators are defined below using the symbols: , , , , and . Each composition operator may have a subscript “E” (e.g., E) that defines a “composition pattern” that is used to tune the semantics of the composition operator. The absence of the composition pattern “E” in the subscript of a composition operator (e.g., ) indicates that the composition pattern “E” is an identity pattern (i.e., no tuning is performed to the semantics of the composition operator).
In addition, the composition operator may specify a “type combination relation” in its superscript. The type combination relation describes the manner in which parameter types of the composition operator are to be combined. One type combination relation is specified for each parameter defined by the composition operator. Each type combination relation specified indicates how to determine the type a parameter of the composed abstraction will take. As defined herein, the type combination relation is defined using the symbols ⊕, which represents the lowest common subtype, and , which represents the greatest common subtype, and the symbols * and ⋄, that range over {⊕, }. The absence of either of these symbols in the superscript of a composition operator indicates that the types during the composition of the parameters do not change.
At 404 in FIG. 4, each expression (e.g., 302 and 304) in each abstraction (e.g., 224 and 226) defined in the abstraction composition operation 222 are unfolded. Unfolding an expression from an abstraction involves: (a) removing the prefix of the abstraction and (b) substituting formal parameter names in each expression with a common (i.e., fresh) parameter name to define open variables. In some embodiments, the formal parameter names may be substituted for more than one common parameter name. Act 404 in FIG. 3 is illustrated in FIG. 3 by unfolding the expressions 302 and 304 into the expressions 306 and 308, respectively.
At 406 in FIG. 4, the unfolded expressions (e.g., expressions 310) are transformed to a reduced expression (e.g., reduced expression 312) using a composition pattern that tunes the semantics of the composition operator. In some instances, this transformation may introduce information that specifies how to combine parameter types. Also in some instances, this transformation may involve using a composition pattern that is an identity pattern.
At 408 in FIG. 4, a prefix is selected (i.e., the selected prefix) that depends on (a) the composition operator and (b) the form of the plurality of abstractions. Abstractions may take one of four forms: a λ-abstraction, a ∇-abstraction, and their recursive variants (which are all defined in detail below). The selected prefix has at least one formal parameter with a type.
At 410 in FIG. 4, the reduced expression (e.g., reduced expression 312) is nested in a composed abstraction (e.g., composed abstraction 308) by: (a) appending the selected prefix (selected at act 408) to the reduced expression; (b) binding the open variables of the reduced expression (introduced at act 404) to the formal parameter of the selected prefix; and (c) computing the type of the formal parameter of the selected prefix in accordance with the type combination relation specified for the composition operator.
A.3 Detailed Example
The following example illustrates the composition of two abstractions Abs1 and Abs2 using the composition operator  defined at [c1] below as:




  
    (
    
      z
      ⁢
      
        
      
      ⁢
      fresh
    
    )
  
  ⁢
  
    
      
        E
        ⁡
        
          (
          
            
            
              
                e
                1
              
              ⁡
              
                [
                
                  z
                  /
                  
                    x
                    1
                  
                
                ]
              
            
            
          
          )
        
      
      ⁢
      
        ⋯
        ⁡
        
          (
          
            
            
              
                e
                n
              
              ⁡
              
                [
                
                  z
                  /
                  
                    x
                    n
                  
                
                ]
              
            
            
          
          )
        
      
      ⁢
            ⁢
      
        
      
      ⁢
      e
    
    
      
        
                    E
          ⊗
        
        ⁢
        
          
        
        ⁢
        
          (
          
            
              λ
              ⁢
              
                
              
              ⁢
              
                
                  x
                  1
                
                :
                
                  
                    t
                    1
                  
                  ·
                  
                    e
                    1
                  
                
              
            
            ,
            ...
            ⁢
            
              
            
            ,
            
              λ
              ⁢
              
                
              
              ⁢
              
                
                  x
                  n
                
                :
                
                  
                    t
                    n
                  
                  ·
                  
                    e
                    n
                  
                
              
            
          
          )
        
      
      →
      
        λ
        ⁢
        
          
        
        ⁢
        
          z
          :
          
            
              t
              x
            
            ·
            e
          
        
      
    
  
  ⁢
  
    [
    
      c
      ⁢
      
        
      
      ⁢
      1
    
    ]
  




where:

“λxn:tn.en” is a lambda abstraction with prefix “λx:t”, in which “λ” identifies a form of abstraction, “x” identifies a formal parameter (i.e., a parameter encapsulated in an abstraction) of type “t”, and “e” is the expression of the abstraction,
“en[z/xn]” means substitute xn for z in the expression en,
“” means the terminal form of an operation (i.e., after possibly several operational steps) reduces to a value,
“” identifies a type combination relation that specifies the greatest common subtype relation,
“e1e2” defines a lazy application in which the expression e2 is passed by a function without first being computed, and
“E” is a composition pattern (i.e., a lambda term that parameterizes the composition operation E(e1, . . . , en)).
Assuming in this example the lazy application “e e” is given by a [β1] reduction defined as:

λx:t.e1e2→e1[e2/x]  [β1]

Also assuming in this example that the abstractions Abs1 and Abs2 are given by:

Abs1≡λx:any .x(where x is a formal parameter of type “any”), and

Abs2≡λx:int. 1 (where x is a formal parameter of type “int”).

Further assuming in this example that the composition pattern “E” of the composition operation Sub is given by:

Sub≡λx:int.λy:int.x−y

Given the above assumptions, the composition of the abstractions Abs1 and Abs2 is expressed as (i.e., at act 402 in FIG. 4):

Sub(Abs1, Abs2)=Sub (λx:any .x, λx:int. 1).

Initially the expressions e of each abstraction are unfolded in accordance with the general form Ee1[z/x1] . . . en[z/xn] by (a) removing the prefix (e.g., “λx:any” and “λx:int”) of each abstraction (i.e., at act 404(1) in FIG. 4) and (b) substituting the formal parameter name “x” in each expression with a common (i.e., fresh) parameter name “z” to provide the unfolded expression (e.g., (i.e., at act 404(2) in FIG. 4):

Subx[z/x]1[z/x′].

Transforming the unfolded expression using the composition pattern Sub provides a reduced expression (i.e., at act 406 in FIG. 4) initially in the form (after substituting “x” for “z” in the expression “e” given by “e[z/x]”):
Subz1, which after expanding in accordance with the composition pattern Sub provides:
λx:int.y:int.x−yz1, which after applying z to x in accordance with [β1] reduction reduces to:
λy:int.z−y1, and which after applying 1 for y in accordance with [β1] reduction reduces to the reduced expression (called “e”):

z−1.

A prefix is selected with a value that depends on the composition operator (e.g., ) and the form of the plurality of abstractions (e.g., Abs1 and Abs2). For this example the selected prefix is “λx:???” (i.e., at act 408 in FIG. 4). Finally, the reduced expression is nested in an abstraction by appending the selected prefix (i.e., at act 410(1) in FIG. 4) as follows:
λx:???.z−1, and binding the open variable “z” to the formal parameter “x” of the selected prefix (i.e., at act 410(2) in FIG. 4) as follows:
λz:???.z−1, and computing the type of the formal parameter of the selected prefix in accordance with the greatest common subtype relation of types “any” and “int” (e.g., any  int≡int) (i.e., at act 410(3) in FIG. 4) as follows to provide the composed abstraction:

λz:int.z−1.

B. General Syntax and Operational Semantics

Operational semantics is described herein using the SOS style described in G. Plotkin's article “A structural approach to operational semantics”, Technical Report DAIMI-FN-19, Computer Sciences Dept., Å rhus university, Denmark, 1981, considering “small step” transitions in order to cover an eventual extension to concurrent languages with interleaving semantics.
A set of definitions is provided of a general abstract syntax of expressions “e” that describes basic constructs for terms of the underlying programming language, where the notation of “e” encompasses imperative and functional expressions. The first set defined in this section specifies functional expressions and the second set defined below in section E specifies imperative expressions.
An “imperative expression” as used herein generally means an expression that involves several sequential computational steps. A “functional expression” as used herein generally means an expression that allows “functional style” programming (i.e., programming that allows solution of problems to be found by defining functions and applying parameters to those functions).
Functional expressions “e”, with types “t”, defined herein include:













e ::= n | x | s |
numerical values, variables, string litterals


e*e |
basic operations (* ε {+, −, *})


if e then e else e |
alternation


λx:t.e | fixf(x:t)=e |
typed lambda abstraction and recursive variant


e(|e|) | e(e) |
lazy and strict application


e ::= true | false |
boolean literals


e == e | e > e |
comparisons


t ::= int | string | bool |
primitive types


t|t |
union of types


T | ⊥ | t → t | t   t
top and bottom type, functions,



recursive functions









The definition of two different applications are described herein: the first definition of “application” (i.e., e1e2) allows lazy application whereas the second definition of “application” (i.e., e1(e2)) allows strict application (i.e., where the parameter must be normalized to a value before substitution, where a value is defined herein as a Boolean or numerical literal, or a (recursive) lambda abstraction).
As used herein, a transition system describes an interpreter of the language through a transition relation which defines the computation of any expression e into a new expression e′, and is noted e→e′. Also, several computation steps such as e→e′→e′′ are abbreviated herein using the notation ee′′. Normalizing computations will reduce the expression e to a term e′ which cannot be further reduced; this particular computation step is noted ee′ and formally defined by:




  
    
      e
      →
      
        
          e
          ′
        
        ⁢
        
          
        
        ⁢
        
          e
          ′
        
        ⁢
              
    
    
      e
      →
      
        o
        ⁢
        
          
        
        ⁢
        
          e
          ′
        
      
    
  
  ⁡
  
    [
    norm
    ]
  




By convention, values are noted v or n, s if they are numeric or string constants. A derivation chain that reduces to a value is noted ev. The notation ee′ is used herein for derivation paths of zero or more steps transforming e in e′.
The following equations define the testing operation semantics:

if true then e2 else e3→e2  [if1]

if false then e2 else e3→e3  [if2]





  
    
      
        
          
            e
            1
          
          →
          
            e
            1
            ′
          
        
        
          
            if
            ⁢
            
              
            
            ⁢
            
              e
              1
            
            ⁢
            
              
            
            ⁢
            then
            ⁢
            
              
            
            ⁢
            
              e
              2
            
            ⁢
            
              
            
            ⁢
            else
            ⁢
            
              
            
            ⁢
            
              e
              3
            
          
          →
          
            if
            ⁢
            
              
            
            ⁢
            
              e
              1
              ′
            
            ⁢
            
              
            
            ⁢
            then
            ⁢
            
              
            
            ⁢
            
              e
              2
            
            ⁢
            
              
            
            ⁢
            else
            ⁢
            
              
            
            ⁢
            
              e
              3
            
          
        
      
    
    
      
        [
        
          if
          ⁢
          
            
          
          ⁢
          3
        
        ]
      
    
  




The semantics of operations on basic types is without surprise defined as (where the meta symbol is given by *ε{+,−,*,>,==}, and where ε evaluates numeric literals into integer):



  
    
      
        
          e
          1
        
        →
        
          e
          1
          ′
        
      
      
        
          
            e
            1
          
          ⁢
          ★
          ⁢
          
            
          
          ⁢
          
            e
            2
          
        
        →
        
          
            e
            1
            ′
          
          ⁢
          
            
          
          ⁢
          ★
          ⁢
          
            
          
          ⁢
          
            e
            2
          
        
      
    
    ⁡
    
      [
      
        left
        ⁢
        ­★
      
      ]
    
  




  
    
      
        
          e
          2
        
        →
        
          e
          2
          ′
        
      
      
        
          υ
          ⁢
          
            
          
          ⁢
          ★
          ⁢
          
            
          
          ⁢
          
            e
            2
          
        
        →
        
          υ
          ⁢
          
            
          
          ⁢
          ★
          ⁢
          
            
          
          ⁢
          
            e
            2
            ′
          
        
      
    
    ⁡
    
      [
      
        right
        ⁢
        ­★
      
      ]
    
  




  
    
      
        
          ɛ
          ⁡
          
            (
            
              n
              3
            
            )
          
        
        =
        
          
            ɛ
            ⁡
            
              (
              
                n
                1
              
              )
            
          
          +
          
            ɛ
            ⁡
            
              (
              
                n
                2
              
              )
            
          
        
      
      
        
          
            n
            1
          
          +
          
            n
            2
          
        
        →
        
          n
          3
        
      
    
    ⁡
    
      [
      add
      ]
    
  




  
    
      
        s
        1
      
      +
      
        s
        2
      
    
    →
    
      
        s
        1
      
      ⁢
      
        
          s
          2
        
        ⁡
        
          [
          cat
          ]
        
      
    
  




  
    
      
        
          ɛ
          ⁡
          
            (
            
              n
              3
            
            )
          
        
        =
        
          
            ɛ
            ⁡
            
              (
              
                n
                1
              
              )
            
          
          ×
          
            ɛ
            ⁡
            
              (
              
                n
                2
              
              )
            
          
        
      
      
        
          
            n
            1
          
          *
          
            n
            2
          
        
        →
        
          n
          3
        
      
    
    ⁡
    
      [
      mul
      ]
    
  




  
    
      
        
          ɛ
          ⁡
          
            (
            
              n
              3
            
            )
          
        
        =
        
          
            ɛ
            ⁡
            
              (
              
                n
                1
              
              )
            
          
          -
          
            ɛ
            ⁡
            
              (
              
                n
                2
              
              )
            
          
        
      
      
        
          
            n
            1
          
          -
          
            n
            2
          
        
        →
        
          n
          3
        
      
    
    ⁡
    
      [
      sub
      ]
    
  



Note for the definitions [eq] and [neq] below, the symbol “=α”, which is known as alpha-equivalence in the lambda calculus theory, is the syntactic equality, up to alpha-substitution (as set forth at the beginning of section D.2 below).




  
    
      
        
          
            
              υ
              1
            
            ⁢
            
              =
              α
            
            ⁢
            
              υ
              2
            
          
          
            
              
                υ
                1
              
              ==
              
                υ
                2
              
            
            →
            true
          
        
        ⁢
        
          [
          eq
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          [
          eq
          ]
        
        ⁢
        
          
            ⫬
            
              (
              
                
                  υ
                  1
                
                ⁢
                
                  =
                  α
                
                ⁢
                
                  υ
                  2
                
              
              )
            
          
          
            
              
                υ
                1
              
              ==
              
                υ
                2
              
            
            →
            false
          
        
        ⁢
        
          [
          neq
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            
              ɛ
              ⁡
              
                (
                
                  n
                  1
                
                )
              
            
            >
            
              ɛ
              ⁡
              
                (
                
                  n
                  2
                
                )
              
            
          
          
            
              
                n
                1
              
              >
              
                n
                2
              
            
            →
            true
          
        
        ⁡
        
          [
          gt
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            
              ɛ
              ⁡
              
                (
                
                  n
                  1
                
                )
              
            
            ≤
            
              ɛ
              ⁡
              
                (
                
                  n
                  2
                
                )
              
            
          
          
            
              
                n
                1
              
              >
              
                n
                2
              
            
            →
            false
          
        
        ⁢
        
          [
          ngt
          ]
        
      
    
    
      
        
      
    
  




Both lazy and strict application evaluate left argument first:



  
    
      
        
          e
          1
        
        →
        
          e
          1
          ′
        
      
      
        
          
            e
            1
          
          ⁡
          
            (
            
              e
              2
            
            )
          
        
        →
        
          
            e
            1
            ′
          
          ⁢
          
            
          
          ⁢
          
            (
            
              e
              2
            
            )
          
        
      
    
    ⁡
    
      [
      
        @
        1
      
      ]
    
  




  
    
      
        
          e
          1
        
        →
        
          e
          1
          ′
        
      
      
        
          
            e
            1
          
          ⁡
          
            (
            
              e
              2
            
            )
          
        
        →
        
          
            e
            1
            ′
          
          ⁢
          
            
          
          ⁢
          
            (
            
              e
              2
            
            )
          
        
      
    
    ⁡
    
      [
      
        @
        2
      
      ]
    
  



The strict application requires (a) a normalized left term and (b) evaluating the parameter before substitution, while lazy application substitutes terms directly.




  
    
      
        e
        2
      
      →
      
        e
        2
        ′
      
    
    
      
        υ
        ⁡
        
          (
          
            e
            2
          
          )
        
      
      →
      
        υ
        (
        
          e
          2
          ′
        
        ⁢
        
          
        
        )
      
    
  
  ⁡
  
    [
    
      @
      3
    
    ]
  




λx:t.e1(v)→e1[v/x]  [β2]

λx:t.e1e2→e1[e2/x]  [β1]

Application on recursive abstractions “f” is performed towards two substitutions: the rewriting of the recursion variable by the recursive abstraction itself and then the usual substitution of the parameter.

fixf(x:t)=e(v)→e[fixf(x:t)=e/f][v/x]  [β3]

As usual in lambda calculi, the substitution operation involved in [β1], [β2] and [β3] must avoid name capture.
C. Additional Type System
Composition operators operate over types. The typing rules set forth below define well typed properties of types. In one embodiment, the type checker 212 includes instructions that determine whether an expression is well typed using a series of logical operations that verify whether an expression is weakly sound in accordance with the typing rules defined herein.
C.1 Defining Sub-Type Relations
Accordingly, this section defines sub-type relations (i.e., subtype properties of types). That is, this section defines how types propagate during composition. More specifically, this section presents a formal type system including a (reflexive and transitive) subtype relation t1t2 (which provides t1 is a subtype of t2), with basic axioms for all type t and expression e. The subtype relations [top] and [bot] are defined as:

tT[top]⊥t  [bot]

Typing assertions are noted herein as e:t (i.e., expression e has type t). A typing environment γ may contain typing assertions over variables, and is used through the γe:t notation, where “” provides that expression e has type t in environment γ. Typically environment γ, x:t means that the current environment contains the assertion that variable x has type t. The typing assertion [sub] is defined as:




  
    
      γ
      ⊳
      
        e
        :
        
          
            
              t
              1
            
            ⁢
            
              
            
            ⁢
            
              t
              1
            
          
          ≼
          t
        
      
    
    
      γ
      ⊳
      
        e
        :
        t
      
    
  
  ⁢
  
    [
    sub
    ]
  




The proposed notations distinguishes between “exact” typing (e::t) and typing by subsumption (e:t). This allows more precise type control, thereby avoiding over generalizing influences due to so called subsumption rule (see [sub] above), while preserving the convenience of subtyping mechanism. The union type provides a simple way to construct a super type by aggregating two types.



  
    
      
        
          γ
          ⊳
          e
          ∷
          t
        
        
          γ
          ⊳
          
            e
            :
            t
          
        
      
      ⁡
      
        [
        Min
        ]
      
    
    ⁢
    
      
        
          
            t
            1
          
          ≼
          
            t
            ⁢
            
              
            
            ⁢
            
              t
              2
            
          
          ≼
          t
        
        
          
            t
            1
          
          ⁢
          
            
            
              
                t
                2
              
              ≼
              t
            
          
        
      
      ⁡
      
        [
        
          U
          ⁢
          
            
          
          ⁢
          1
        
        ]
      
    
  




  
    
      
        
          t
          ≼
          
            t
            1
          
        
        
          t
          ≼
          
            
              t
              1
            
            ⁢
            
              
              
                t
                2
              
            
          
        
      
      ⁡
      
        [
        
          U
          ⁢
          
            
          
          ⁢
          2
        
        ]
      
    
    ⁢
    
      
    
    ⁢
    
      
        
          t
          ≼
          
            t
            2
          
        
        
          t
          ≼
          
            
              t
              1
            
            ⁢
            
              
              
                t
                2
              
            
          
        
      
      ⁡
      
        [
        
          U
          ⁢
          
            
          
          ⁢
          3
        
        ]
      
    
  



The proposed type system makes use of two relations over types.
Definition 1: Greatest common subtype .
Let  be the language generated by the grammar of types, where  is a total mapping from × into  such that:
∀t1, t2t1t2 is the greatest common subtype of t1 and t2.
Definition 2: Lowest common supertype .
Let  be the language generated by the grammar of types, where  is a relation from × into  such that:
∀, t2t1⊕t2 is the greatest common subtype of t1 and t2.
Note that common subtypes or super types always exist because of the definition of T and ⊥ types. The ⊕ relation (used for instance in the [If] rule) is more abstract than the type union, since for instance int ⊕ string is either int|string or int|string|int. The [If] rule allows therefore precise and flexible typing of conditional statements, and the same for lambda abstractions (i.e., rules [f2,f2b] and [Fix,Fixb]).
The structural equality allows a natural treatment of types and their properties.
Definition 3: Structural type equality.

t1=t2 t1t2 and t2t1 

C.2 Typing Rules for Defining Well Typed Properties of Terms
The following set of typing equations covers additional logical assertions needed to handle the static semantics of the defined calculus (*ε{+,−,*}). (Note that  indicates that no typing context information is necessary.)

∅true::bool  [b1]

∅false::bool  [b2]

∅n::int  [i]

∅s::string  [s]

γ, x:tx::t  [var]





  
    
      
        
          
            
              t
              3
            
            ≼
            
              
                t
                1
              
              ⁢
              
                
              
              ⁢
              
                t
                2
              
            
            ≼
            
              t
              4
            
          
          
            
              t
              1
            
            →
            
              
                
                  t
                  2
                
                ≼
                
                  t
                  3
                
              
              →
              
                t
                4
              
            
          
        
        ⁢
        
          [
          fsub
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            
              t
              3
            
            ≼
            
              
                t
                1
              
              ⁢
              
                
              
              ⁢
              
                t
                2
              
            
            ≼
            
              t
              4
            
          
          
            
              t
              1
            
            →
            
              
                
                  t
                  2
                
                ≼
                
                  t
                  3
                
              
              →
              
                t
                4
              
            
          
        
        ⁡
        
          [
          fsub2
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            γ
            ⊳
            
              
                e
                1
              
              :
              
                
                  bool
                  ⁢
                  
                    
                  
                  ⁢
                  γ
                
                ⊳
                
                  e
                  2
                
                ∷
                
                  
                    t
                    1
                  
                  ⁢
                  
                    
                  
                  ⁢
                  γ
                
                ⊳
                
                  e
                  3
                
                ∷
                
                  t
                  2
                
              
            
          
          
            γ
            ⊳
            
              if
              ⁢
              
                
              
              ⁢
              
                e
                1
              
              ⁢
              
                
              
              ⁢
              then
              ⁢
              
                
              
              ⁢
              
                e
                2
              
              ⁢
              
                
              
              ⁢
              else
              ⁢
              
                
              
              ⁢
              
                e
                3
              
            
            ∷
            
              
                t
                1
              
              ⊕
              
                t
                2
              
            
          
        
        ⁢
        
          [
          If
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            γ
            ⊳
            
              
                e
                1
              
              :
              
                
                  string
                  ⁢
                  
                    
                  
                  ⁢
                  γ
                
                ⊳
                
                  
                    e
                    2
                  
                  :
                  string
                
              
            
          
          
            γ
            ⊳
            
              
                e
                1
              
              +
              
                e
                2
              
            
            ∷
            string
          
        
        ⁢
        
          [
          
            s
            -
            +
          
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            γ
            ⊳
            
              
                e
                1
              
              :
              
                
                  int
                  ⁢
                  
                    
                  
                  ⁢
                  γ
                
                ⊳
                
                  
                    e
                    2
                  
                  :
                  int
                
              
            
          
          
            γ
            ⊳
            
              
                e
                1
              
              ⁢
              ★
              ⁢
              
                
              
              ⁢
              
                e
                2
              
            
            ∷
            int
          
        
        ⁢
        
          [
          i­★
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            γ
            ⊳
            
              
                e
                1
              
              :
              
                ⊤
                
                  
                
                ⁢
                
                  γ
                  ⊳
                  
                    
                      e
                      2
                    
                    :
                    ⊤
                  
                
              
            
          
          
            γ
            ⊳
            
              e
              1
            
            ==
            
              e
              2
            
            ∷
            bool
          
        
        ⁡
        
          [
          t­eq
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            γ
            ⊳
            
              
                e
                1
              
              :
              
                
                  int
                  ⁢
                  
                    
                  
                  ⁢
                  γ
                
                ⊳
                
                  
                    e
                    2
                  
                  :
                  int
                
              
            
          
          
            γ
            ⊳
            
              e
              1
            
            >
            
              e
              2
            
            ∷
            bool
          
        
        ⁢
        
          [
          t­gt
          ]
        
      
    
    
      
        
      
    
  




The typing of abstraction and application can be classically handled through the following equations. (Note also that the meta symbol  in [a] ranges over symbols → and .)




  
    
      
        
          
            x
            ∉
            
              
                dom
                ⁡
                
                  (
                  γ
                  )
                
              
              ⁢
              
                
              
              ⁢
              γ
            
          
          ,
          
            x
            :
            
              
                t
                1
              
              ⊳
              e
              ∷
              
                t
                2
              
            
          
        
        
          γ
          ⊳
          
            λ
            ⁢
            
              
            
            ⁢
            
              x
              :
              
                
                  
                    
                      t
                      1
                    
                    ·
                    e
                  
                  ∷
                  
                    t
                    1
                  
                
                →
                
                  t
                  2
                
              
            
          
        
      
    
    
      
        [
        f
        ]
      
    
  
  
    
      
        
          f
          ,
          
            x
            ∉
            
              
                dom
                ⁡
                
                  (
                  γ
                  )
                
              
              ⁢
              
                
              
              ⁢
              γ
            
          
          ,
          
            x
            :
            
              t
              1
            
          
          ,
          
            f
            :
            
              
                
                  t
                  1
                
                ⁢
                                ⁢
                
                  t
                  2
                
              
              ⊳
              e
              ∷
              
                t
                2
              
            
          
        
        
          
            γ
            ⊳
            
              fix
              ⁢
              
                
                  
                
                ⁢
                
                  
                
              
              ⁢
              
                f
                ⁡
                
                  (
                  
                    x
                    :
                    
                      t
                      1
                    
                  
                  )
                
              
            
          
          =
          
            e
            ∷
            
              
                t
                1
              
              ⁢
                            ⁢
              
                t
                2
              
            
          
        
      
    
    
      
        [
        Fix
        ]
      
    
  
  
    
      
        
          
            γ
            ⊳
            
              e
              1
            
            ∷
            
              t
              1
            
          
          →
          
            
              
                t
                2
              
              ⁢
              
                
              
              ⁢
              γ
            
            ⊳
            
              
                e
                2
              
              :
              
                t
                1
              
            
          
        
        
          γ
          ⊳
          
            
              e
              1
            
            ⁡
            
              (
              
                e
                2
              
              )
            
          
          ∷
          
            t
            2
          
        
      
    
    
      
        [
        a
        ]
      
    
  
  
    
      
        
          
            γ
            ⊳
            
              e
              1
            
            ∷
            
              t
              1
            
          
          →
          
            
              
                t
                2
              
              ⁢
              
                
              
              ⁢
              γ
            
            ⊳
            
              
                e
                2
              
              :
              
                t
                1
              
            
          
        
        
          γ
          ⊳
          
            
              e
              1
            
            ⁡
            
              (
              
                e
                2
              
              )
            
          
          ∷
          
            t
            2
          
        
      
    
    
      
        [
        a2
        ]
      
    
  




The precise typing of some functional abstraction Aλx:int|string.x+x is not possible through this conventional approach, although it is correct from the execution point of view. This expression is defined herein as type int|string→int|string since A(10)  20 and A(‘10’)  ‘1010’. In addition, the following is asserted as well A(10):int and A(‘10’):string. The following sets of equations provide more typing power both for non-recursive and recursive abstractions (where in the equation [Fix+]tijε{t1, . . . , tn} and all distinct, and in the equation [a+]i1, . . . , ik ε[1,n] and all distinct).




  
    
      
        
          
            x
            ∉
            
              
                dom
                ⁡
                
                  (
                  γ
                  )
                
              
              ⁢
              
                
              
              ⁢
              γ
            
          
          ,
          
            x
            :
            
              
                t
                1
              
              ⊳
              e
              ∷
              
                
                  t
                  1
                  ′
                
                ⁢
                
                  
                
                ⁢
                ⋯
                ⁢
                
                  
                
                ⁢
                γ
              
            
          
          ,
          
            x
            :
            
              
                t
                n
              
              ⊳
              e
              ∷
              
                e
                N
                ′
              
            
          
        
        
          
            
              
                γ
                ⊳
                
                  λ
                  ⁢
                  
                    
                  
                  ⁢
                  
                    x
                    :
                    
                      
                        
                          t
                          1
                        
                        ⁢
                        
                          
                          ⋯
                          
                        
                        ⁢
                        
                          
                            t
                            n
                          
                          ·
                          e
                        
                      
                      ∷
                      
                        
                          (
                          
                            
                              t
                              1
                            
                            →
                            
                              t
                              1
                              ′
                            
                          
                          )
                        
                        ⊕
                        ⋯
                        ⊕
                      
                    
                  
                
              
            
          
          
            
              
                
                  (
                  
                    
                      t
                      n
                    
                    →
                    
                      t
                      n
                      ′
                    
                  
                  )
                
                ⊕
                
                  (
                  
                    
                      
                        t
                        1
                      
                      ⁢
                      
                        
                        ⋯
                        
                      
                      ⁢
                      
                        t
                        n
                      
                    
                    →
                    
                      
                        t
                        1
                        ′
                      
                      ⁢
                      
                        
                        ⋯
                        
                      
                      ⁢
                      
                        t
                        n
                        ′
                      
                    
                  
                  )
                
              
            
          
        
      
    
    
      
        [
        
          f
          +
        
        ]
      
    
  
  
    
      
        
          
            
              
                f
                ,
                
                  x
                  ∉
                  
                    
                      dom
                      ⁡
                      
                        (
                        γ
                        )
                      
                    
                    ⁢
                    
                      
                    
                    ⁢
                    γ
                  
                
                ,
                
                  x
                  :
                  
                    t
                    1
                  
                
                ,
                
                  f
                  :
                  
                    
                      
                        t
                        1
                      
                      ⁢
                                            ⁢
                      
                        t
                        1
                        ′
                      
                    
                    ⊳
                  
                
              
            
          
          
            
              
                
                  
                    e
                    ⁢
                    ::
                    ⁢
                    
                      t
                      1
                      ′
                    
                  
                  ⁢
                  
                    
                  
                  ⁢
                  ...
                  ⁢
                  
                    
                  
                  ⁢
                  γ
                
                ,
                
                  x
                  :
                  
                    t
                    n
                  
                
                ,
                
                  f
                  :
                  
                    
                      
                        t
                        n
                      
                      ⁢
                                            ⁢
                      
                        t
                        n
                        ′
                      
                    
                    ⊳
                    
                      e
                      ⁢
                      ::
                      ⁢
                      
                        t
                        n
                        ′
                      
                    
                  
                
              
            
          
        
        
          
            
              
                
                  γ
                  ⊳
                  
                    fix
                    ⁢
                    
                      
                    
                    ⁢
                    
                      f
                      ⁡
                      
                        (
                        
                          x
                          :
                          
                            
                              t
                              1
                            
                            ⁢
                            
                              
                              ...
                              
                            
                            ⁢
                            
                              t
                              n
                            
                          
                        
                        )
                      
                    
                  
                
                =
                
                  
                    
                      e
                      ⁢
                      ::
                      ⁢
                      
                        t
                        1
                      
                    
                    ⁢
                                        ⁢
                    
                      t
                      1
                      ′
                    
                  
                  ⊕
                  ⋯
                  ⊕
                
              
            
          
          
            
              
                
                  
                    t
                    n
                  
                  ⁢
                                    ⁢
                  
                    t
                    n
                    ′
                  
                
                ⊕
                
                  
                    t
                    1
                  
                  ⁢
                  
                    
                    ...
                    
                  
                  ⁢
                  
                    t
                    n
                  
                  ⁢
                                    ⁢
                  
                    t
                    1
                    ′
                  
                  ⁢
                  
                    
                    ...
                    
                  
                  ⁢
                  
                    t
                    n
                    ′
                  
                
              
            
          
        
      
    
    
      
        [
        
          Fix
          +
        
        ]
      
    
  
  
    
      
        
          
            
              
                
                  
                    γ
                    ⊳
                    
                      e
                      1
                    
                    ∷
                    
                      t
                      1
                    
                  
                  →
                  
                    
                      
                        t
                        1
                        ′
                      
                      ⁢
                      
                        
                        ⋯
                        
                      
                      ⁢
                      
                        
                      
                      ⁢
                      
                        t
                        n
                      
                    
                    →
                  
                
              
            
            
              
                
                  
                    t
                    n
                    ′
                  
                  ⁢
                  
                    {
                    
                      
                        
                          
                            γ
                            ⊳
                            
                              
                                e
                                2
                              
                              :
                              
                                
                                  
                                    t
                                    11
                                  
                                  ⁢
                                  
                                    
                                  
                                  ⁢
                                  ⋯
                                  ⁢
                                  
                                    
                                  
                                  ⁢
                                  γ
                                
                                ⊳
                                
                                  
                                    e
                                    2
                                  
                                  :
                                  
                                    t
                                    
                                      1
                                      ⁢
                                      k
                                    
                                  
                                
                              
                            
                          
                        
                        
                          
                            
                              t
                              11
                            
                            ≼
                            ⋯
                            ≼
                            
                              t
                              
                                1
                                ⁢
                                k
                              
                            
                          
                        
                      
                      
                        
                          ⋮
                        
                        
                          ⋮
                        
                      
                      
                        
                          
                            γ
                            ⊳
                            
                              
                                e
                                2
                              
                              :
                              
                                
                                  
                                    t
                                    
                                      j
                                      ⁢
                                      
                                        
                                      
                                      ⁢
                                      1
                                    
                                  
                                  ⁢
                                  
                                    
                                  
                                  ⁢
                                  ⋯
                                  ⁢
                                  
                                    
                                  
                                  ⁢
                                  γ
                                
                                ⊳
                                
                                  
                                    e
                                    2
                                  
                                  :
                                  
                                    t
                                    jm
                                  
                                
                              
                            
                          
                        
                        
                          
                            
                              t
                              11
                            
                            ≼
                            ⋯
                            ≼
                            
                              t
                              
                                1
                                ⁢
                                k
                              
                            
                          
                        
                      
                    
                  
                
              
            
          
          ⁢
          
            
          
        
        
          γ
          ⊳
          
            
              e
              1
            
            ⁡
            
              (
              
                e
                2
              
              )
            
          
          ∷
          
            
              t
              11
              ′
            
            ⊕
            
              
            
            ⁢
            ⋯
            ⁢
            
              
            
            ⊕
            
              t
              
                j
                ⁢
                
                  
                
                ⁢
                1
              
              ′
            
          
        
      
    
    
      
        [
        
          a
          +
        
        ]
      
    
  
  
    
      
        
          
            γ
            ⊳
            
              e
              1
            
            ∷
            
              t
              1
            
          
          →
          
            
              
                t
                2
              
              ⁢
              
                
                ⋯
                
              
              ⁢
              
                t
                n
              
            
            →
            
              
                
                  t
                  n
                  ′
                
                ⁢
                
                  
                
                ⁢
                γ
              
              ⊳
              
                
                  e
                  2
                
                :
                
                  
                    
                      t
                      
                        i
                        ⁢
                        
                          
                        
                        ⁢
                        1
                      
                    
                    ⁢
                    
                      
                    
                    ⁢
                    ⋯
                    ⁢
                    
                      
                    
                    ⁢
                    γ
                  
                  ⊳
                  
                    
                      e
                      2
                    
                    :
                    
                      t
                      ik
                    
                  
                
              
            
          
        
        
          γ
          ⊳
          
            
              e
              1
            
            ⁡
            
              (
              
                e
                2
              
              )
            
          
          ∷
          
            
              t
              
                i
                ⁢
                
                  
                
                ⁢
                1
              
              ′
            
            ⊕
            
              
            
            ⁢
            ⋯
            ⁢
            
              
            
            ⊕
            
              t
              ik
              ′
            
          
        
      
    
    
      
        [
        
          a2
          +
        
        ]
      
    
  




D. The Composition of Functional Abstractions

The composition of abstractions specified in this section are performed through: an n-ary (parametric) operator that follows the syntax E(e1, . . . , en), where E is a lambda term that parameterizes the operation; and one unary operator (e). The semantics of the first composition is defined by the following three rules [c0], [c1], and [c2]:




  
    
      
        
          
            e
            i
          
          →
          
            e
            i
            ′
          
        
        
          
            
                            E
            
            ⁢
            
              (
              
                
                  v
                  1
                
                ,
                ...
                ⁢
                
                  
                
                ,
                
                  e
                  i
                
                ,
                ...
                ⁢
                
                  
                
                ,
                
                  e
                  n
                
              
              )
            
          
          →
          
            
                            E
            
            ⁢
            
              (
              
                
                  v
                  1
                
                ,
                ...
                ⁢
                
                  
                
                ,
                
                  e
                  i
                  ′
                
                ,
                ...
                ⁢
                
                  
                
                ,
                
                  e
                  n
                
              
              )
            
          
        
      
    
    
      
        [
        c0
        ]
      
    
  




Rule [c0] shows that each operand is normalized, following a left to right order. The next rule [c1] shows how the operator reduces to its terminal form when all operands are normalized to lambda abstractions as follows:




  
    
      
        
          (
          
            z
            ⁢
            
              
            
            ⁢
            fresh
          
          )
        
        ⁢
        
          
            
              E
              ⁡
              
                (
                
                  
                    e
                    1
                  
                  ⁡
                  
                    [
                    
                      z
                      /
                      
                        x
                        1
                      
                    
                    ]
                  
                
                )
              
            
            ⁢
            
              ⋯
              ⁡
              
                (
                
                  
                    e
                    n
                  
                  ⁡
                  
                    [
                    
                      z
                      /
                      
                        x
                        n
                      
                    
                    ]
                  
                
                )
              
            
            ⁢
                        ⁢
                        ⁢
            e
          
          
            
              
                                E
              
              ⁢
              
                (
                
                  
                    λ
                    ⁢
                    
                      
                    
                    ⁢
                    
                      
                        x
                        1
                      
                      :
                      
                        t
                        ·
                        
                          e
                          1
                        
                      
                    
                  
                  ,
                  ...
                  ⁢
                  
                    
                  
                  ,
                  
                    λ
                    ⁢
                    
                      
                    
                    ⁢
                    
                      
                        x
                        n
                      
                      :
                      
                        t
                        ·
                        
                          e
                          n
                        
                      
                    
                  
                
                )
              
            
            →
            
              λ
              ⁢
              
                
              
              ⁢
              
                z
                :
                
                  t
                  ·
                  e
                
              
            
          
        
      
    
    
      
        [
        c1
        ]
      
    
  




The composition of (at least) one recursive lambda abstraction produces a recursive lambda abstraction reduced to its terminal form as follows in rule [c2]:




  
    
      
        
          (
          
            F
            ,
            
              z
              ⁢
              
                
              
              ⁢
              fresh
            
          
          )
        
        ⁢
        
          
            
              E
              ⁡
              
                (
                
                  
                    e
                    1
                  
                  ⁡
                  
                    [
                    
                      z
                      /
                      
                        x
                        1
                      
                    
                    ]
                  
                
                )
              
            
            ⁢
            
              ⋯
              ⁡
              
                (
                
                  
                    e
                    n
                  
                  ⁡
                  
                    [
                    
                      
                        F
                        /
                        
                          f
                          i
                        
                      
                      ,
                      
                        z
                        /
                        
                          x
                          i
                        
                      
                    
                    ]
                  
                
                )
              
            
            ⁢
            
              
            
            ⁢
            ⋯
            ⁢
            
              
            
            ⁢
            
              (
              
                
                  e
                  n
                
                ⁡
                
                  [
                  
                    z
                    /
                    
                      x
                      n
                    
                  
                  ]
                
              
              )
            
            ⁢
                        ⁢
                        ⁢
            e
          
          
            
              
                
                                    E
                
                ⁢
                
                  (
                  
                    
                      λ
                      ⁢
                      
                        
                      
                      ⁢
                      
                        
                          x
                          1
                        
                        :
                        
                          t
                          ·
                          
                            e
                            1
                          
                        
                      
                    
                    ,
                    ...
                    ⁢
                    
                      
                    
                    ,
                    
                      
                        fix
                        ⁢
                        
                          
                        
                        ⁢
                        
                          
                            f
                            i
                          
                          (
                          
                            
                          
                          ⁢
                          
                            
                              x
                              i
                            
                            :
                            t
                          
                          )
                        
                      
                      =
                      
                        e
                        i
                      
                    
                    ,
                    ...
                    ⁢
                    
                      
                    
                    ,
                    
                      λ
                      ⁢
                      
                        
                      
                      ⁢
                      
                        
                          x
                          n
                        
                        :
                        
                          t
                          ·
                          
                            e
                            n
                          
                        
                      
                    
                  
                  )
                
              
              →
              
                fix
                ⁢
                
                  
                    
                  
                  ⁢
                  
                    
                  
                
                ⁢
                F
                ⁢
                
                  
                
                ⁢
                
                  (
                  
                    
                  
                  ⁢
                  
                    z
                    :
                    t
                  
                  )
                
              
            
            =
            e
          
        
      
    
    
      
        [
        c2
        ]
      
    
  




The semantics of the second operator are defined by the following two rules [c3a] and [c3]:




  
    
      
        
          e
          →
          
            e
            ′
          
        
        
          
                        ⁢
            
              (
              e
              )
            
          
          →
          
                        ⁢
            
              (
              
                e
                ′
              
              )
            
          
        
      
    
    
      
        [
        c3a
        ]
      
    
  




(f fresh) (λx:t.e)→fix f(x:t)=f(e)  [c3]

D.1 Typing of Composition Operators
The composition operators are typed as follows (note that in this and other typing sections the symbol “→” means returns, where in other sections not concerning typing, it means transforms):




  
    
      
        i
        ∈
        
          
            [
            
              1
              ,
              n
            
            ]
          
          ⁢
          
            
              
                γ
                ⊳
                E
                ∷
                
                  t
                  1
                  ′
                
              
              →
              
                ⋯
                →
                
                  
                    t
                    n
                    ′
                  
                  →
                  
                    
                      
                        t
                        2
                      
                      ⁢
                      
                        
                      
                      ⁢
                      γ
                    
                    ⊳
                    
                      
                        e
                        i
                      
                      :
                      
                        
                          t
                          1
                        
                        →
                        
                          t
                          i
                          ′
                        
                      
                    
                  
                
              
            
            
              
                γ
                ⊳
                
                  
                                        E
                  
                  ⁢
                  
                    (
                    
                      
                        e
                        1
                      
                      ,
                      ...
                      ⁢
                      
                        
                      
                      ,
                      
                        e
                        n
                      
                    
                    )
                  
                
                ∷
                
                  t
                  1
                
              
              →
              
                t
                2
              
            
          
        
      
    
    
      
        [
        
          C
          ⁢
          
            -
          
          ⁢
          1
        
        ]
      
    
  




For all i, j ε[1,n], i≠j:




  
    
      
        
          
            
              
                
                  γ
                  ⊳
                  E
                  ∷
                  
                    t
                    1
                    ′
                  
                
                →
                
                  ⋯
                  →
                  
                    
                      t
                      n
                      ′
                    
                    →
                  
                
              
            
          
          
            
              
                
                  
                    
                      t
                      2
                    
                    ⁢
                    
                      
                    
                    ⁢
                    γ
                  
                  ⊳
                  
                    e
                    i
                  
                  ∷
                  
                    t
                    1
                  
                
                →
                
                  
                    
                      t
                      i
                      ′
                    
                    ⁢
                    
                      
                    
                    ⁢
                    γ
                  
                  ⊳
                  
                    
                      e
                      j
                    
                    :
                    
                      
                        t
                        1
                      
                      ⁢
                                            ⁢
                      
                        t
                        j
                        ′
                      
                    
                  
                
              
            
          
        
        
          γ
          ⊳
          
            
                            E
            
            ⁢
            
              (
              
                
                  e
                  1
                
                ,
                ...
                ⁢
                
                  
                
                ,
                
                  e
                  n
                
              
              )
            
          
          ∷
          
            
              t
              1
            
            ⁢
                        ⁢
            
              t
              2
            
          
        
      
    
    
      
        [
        
          C
          ⁢
          
            -
          
          ⁢
          2
        
        ]
      
    
  








  
    
      
        
          
            γ
            ⊳
            e
            ∷
            
              t
              1
            
          
          →
          
            t
            2
          
        
        
          γ
          ⊳
          
                        ⁢
            
              (
              e
              )
            
          
          ∷
          
            
              t
              1
            
            ⁢
                        ⁢
            
              t
              2
            
          
        
      
    
    
      
        [
        F
        ]
      
    
  




D.2 Computational Equivalence
This section defines an equivalence over terms of the calculus defined herein, noted “ ̃”, up to α-equivalence “=α” (i.e., two terms are α-equivalent if there exists a substitution which brings the terms to syntactic equality).
Definition 4: Computational Equivalence “ ̃” is given by:

e1 ̃e2 iff e1v1 and e2v2 and v1=αv2 

It may be shown that “ ̃” is an equivalence relation, i.e., reflexive, symmetric and transitive (assuming that “=α” is an equivalence relation also).
D.3 Application to the Computation of Numeric Series
This section provides examples of the application of composition operators to the computation of numeric series. Consider the recursive function “Fact” which computes the factorial product of any positive integer “x” as follows:

Fact fix f (x:int)=if x>1 then x*f(x−1) else x 

Applied to 4, “Fact” returns 4!=4×3×2×1 (i.e., Fact (4)24). In addition, consider the following functions “S” and “Fibo” (which computes the Fibonacci number of rank “x”):

Sfix f(x:int)=if x>1 then x+f(x−1) else x 

Fibofix f(x:int)=if x>1 then f(x−2)+f(x−1) else x 

Considering now the function “S” which applied to 4 returns 4+3+2+1 (i.e., S(4)10), it can be observed there exists a strong similarity between the structure of the code for the functions “Fact” and “S”. In addition, a similar structure for the code can be observed between the functions “Fact” and “Fibo”.
The composition operators defined herein are advantageously adapted to capture “patterns” in the example functions (e.g., Fact, S, and Fibo) as the composition of fewer fundamental lambda abstractions, some of which are reused several times in order to build the following  ̃-equivalent abstractions:

















Id
 
λx:int.x



Add
 
λx:int.λy:int.x + y



Sub
 
λx:int.λy:int.x − y



Mul
 
λx:int.λy:int.x * y



If
 
λx:int.λy:int.if x > 1 then y else x










Proposition 1: Is given by:

















let A    Sub(Id, λx:int.1)
then
A ~ λx:int.x − 1



let B    Sub(Id, λx:int.2)
then
B ~ λx:int.x − 2










Proving proposition 1 is a straightforward application of [c1] on A and B (defined above) that result in a lambda term which cannot be further reduced and is an α-equivalent to “λx:int.x−1”.
Proposition 2: Is given by:












 If(Id, Mul(Id, (A))) ~ Fact


 If(Id, Add(Id, (A))) ~ S


 If(Id, Add( (B), (A))) ~ Fibo









In proving proposition 2, a derivation path is produced for the function “Fact” as follows:














 If(Id, Mul(Id, (A)))
 
 If(Id, Mul(Id,fixF(z:int)=F(z − 1)))



 
 If(Id,fixF(z′:int)=z′ * F(z′ − 1))



 
fixF′(z′′:int)=if z′′ > 1 then z′′ * F′(z′′ − 1)




else z′′









where a, b, and c correspond to:

    ac0.c0.c3
    bc0, c2, @2, β1, β1 
    cc2, @2, β1, β1 


Proposition 3 (which provides that during composition basic building blocks can be reused) is given by:















let Z   λa:int → int → int.λb:int → int If(Id, a(b, (A)))













Z(Mul)(Id) ~ Fact



then
{open oversize brace}  
Z(Add)(Id) ~ S





Z(Add)( (B)) ~ Fibo










It will be appreciated that the obtained reuse is “syntactic”, as opposed to the functional reuse which is related to runtime factorization of program instructions. As a consequence, the result of the composition will execute as fast as the original abstraction (e.g., Fact). However, standard functional composition will not benefit from similar efficiencies, with patterns such as:

fix f(x:int)=if x>1 then Mul(x)(f(Sub(x)(1))) else x 

or with more abstract patterns such as:

Wλf:int→int→int.λg:int→int→int.fixF(x:int)=if x>1 then f(x)(F(g(x)(1))) else x 

which allows equivalent computation after installation of:
W(Mul)(Sub)(4) ̃Fact(4) and W(Add)(Sub)(4) ̃S(4)
In terms of computation costs, if W(Mul)(Sub)w and Z(Mul)(Id)  z then w(n) computes n! through “8×(n−1)+1” steps versus “4×(n−1)+1” for z(n).
D.4 Handling Subtype Polymorphism (Generalization)
The definitions above for [c1] and [c2] require all parameters of functional abstractions to share the same type. This, however, is a little too restrictive. It would therefore be better for instance to use the definition “Iλx:T.x” rather than the earlier definition “λx:int.x”, since the first definition is a more general identity function. However, correct typing for the composition needs to be ensured. For example, the expression:

Mul(I,λx:int.x−1)

cannot be typed (i.e., Mul:int→int→int does not yield Tint). Accordingly, the following polymorphic variants for [c1], [c2], [C−1], [C−2] (iε[1,n], t×=t1  . . .  tn and t+=t1 ⊕ . . . ⊕ tn) are given by:




  
    
      
        
          
        
        ⁢
        
          
            (
            
              z
              ⁢
              
                
              
              ⁢
              fresh
            
            )
          
          ⁢
          
            
              
                E
                ⁡
                
                  (
                  
                    
                      e
                      1
                    
                    ⁡
                    
                      [
                      
                        z
                        /
                        
                          x
                          1
                        
                      
                      ]
                    
                  
                  )
                
              
              ⁢
              
                ⋯
                ⁡
                
                  (
                  
                    
                      e
                      n
                    
                    ⁡
                    
                      [
                      
                        z
                        /
                        
                          x
                          n
                        
                      
                      ]
                    
                  
                  )
                
              
              ⁢
                            ⁢
                            ⁢
              e
            
            
              
                
                                    ⁢
                  
                    
                  
                
                E
                ⊕
              
              ⁢
              
                
                  (
                  
                    
                      λ
                      ⁢
                      
                        
                      
                      ⁢
                      
                        
                          x
                          1
                        
                        :
                        
                          
                            t
                            1
                          
                          ·
                          
                            e
                            1
                          
                        
                      
                    
                    ,
                    ...
                    ⁢
                    
                      
                    
                    ,
                    
                      λ
                      ⁢
                      
                        
                      
                      ⁢
                      
                        
                          x
                          n
                        
                        :
                        
                          
                            t
                            n
                          
                          ·
                          
                            e
                            n
                          
                        
                      
                    
                  
                  )
                
                →
                
                  λ
                  ⁢
                  
                    
                  
                  ⁢
                  
                    z
                    :
                    
                      
                        t
                        x
                      
                      ·
                      e
                    
                  
                
              
            
          
        
      
    
    
      
        [
        c1
        ]
      
    
  
  
    
      
        
          (
          
            F
            ,
            
              z
              ⁢
              
                
              
              ⁢
              fresh
            
          
          )
        
        ⁢
        
          
            (
            
              
                E
                ⁡
                
                  (
                  
                    
                      e
                      1
                    
                    ⁡
                    
                      [
                      
                        z
                        /
                        
                          x
                          1
                        
                      
                      ]
                    
                  
                  )
                
              
              ⁢
              
                ⋯
                ⁡
                
                  (
                  
                    
                      e
                      i
                    
                    ⁡
                    
                      [
                      
                        
                          F
                          /
                          
                            f
                            i
                          
                        
                        ,
                        
                          z
                          /
                          
                            x
                            i
                          
                        
                      
                      ]
                    
                  
                  )
                
              
              ⁢
              
                
              
              ⁢
              ⋯
              ⁢
              
                
              
              ⁢
              
                (
                
                  
                    e
                    n
                  
                  ⁡
                  
                    [
                    
                      z
                      /
                      
                        x
                        n
                      
                    
                    ]
                  
                
                )
              
              ⁢
                            ⁢
                            ⁢
              e
            
            )
          
          
            
              
                
                  (
                  
                    
                      
                                                ⁢
                        
                          
                        
                      
                      E
                      ⊕
                    
                    ⁢
                    
                      (
                      
                        
                          λ
                          ⁢
                          
                            
                          
                          ⁢
                          
                            
                              x
                              1
                            
                            :
                            
                              
                                t
                                1
                              
                              ·
                              
                                e
                                1
                              
                            
                          
                        
                        ,
                        ...
                        ⁢
                        
                          
                        
                        ,
                        
                          
                            fix
                            ⁢
                            
                              
                            
                            ⁢
                            
                              f
                              i
                            
                            ⁢
                            
                              (
                              
                                
                              
                              ⁢
                              
                                
                                  x
                                  i
                                
                                :
                                
                                  t
                                  i
                                
                              
                              )
                            
                          
                          =
                        
                      
                    
                  
                
              
            
            
              
                
                  
                    
                      
                        
                          
                            e
                            i
                          
                          ,
                          ...
                          ⁢
                          
                            
                          
                          ,
                          
                            λ
                            ⁢
                            
                              
                            
                            ⁢
                            
                              
                                x
                                n
                              
                              :
                              
                                
                                  t
                                  n
                                
                                ·
                                
                                  e
                                  n
                                
                              
                            
                          
                        
                        )
                      
                      →
                      
                        fix
                        ⁢
                        
                          
                        
                        ⁢
                        F
                        ⁢
                        
                          
                        
                        ⁢
                        
                          (
                          
                            
                          
                          ⁢
                          
                            z
                            :
                            
                              t
                              x
                            
                          
                          )
                        
                      
                    
                    =
                    e
                  
                  )
                
              
            
          
        
      
    
    
      
        [
        c2
        ]
      
    
  
  
    
      
        
          
        
        ⁢
        
          
            
              γ
              ⊳
              E
              ∷
              
                t
                1
                ′
              
            
            →
            
              ⋯
              →
              
                
                  t
                  n
                  ′
                
                →
                
                  
                    
                      t
                      2
                    
                    ⁢
                    
                      
                    
                    ⁢
                    γ
                  
                  ⊳
                  
                    
                      e
                      i
                    
                    :
                    
                      
                        t
                        x
                      
                      →
                      
                        t
                        2
                      
                    
                  
                
              
            
          
          
            
              
                
                  
                    γ
                    (
                    
                      ⊳
                                          
                    ⁢
                    
                      
                    
                    )
                  
                  E
                  ⊕
                
                ⁢
                
                  (
                  
                    
                      e
                      1
                    
                    ,
                    ...
                    ⁢
                    
                      
                    
                    ,
                    
                      e
                      n
                    
                  
                  )
                
              
              ∷
              
                t
                x
              
            
            →
            
              t
              2
            
          
        
      
    
    
      
        [
        
          C
          ⁢
          
            -
          
          ⁢
          1
          ⁢
          a
        
        ]
      
    
  
  
    
      
        
          
        
        ⁢
        
          
            
              
                
                  
                    γ
                    ⊳
                    E
                    ∷
                    
                      t
                      1
                      ′
                    
                  
                  →
                  
                    ⋯
                    →
                    
                      
                        t
                        n
                        ′
                      
                      →
                      
                        
                          
                            t
                            2
                          
                          ⁢
                          
                            
                          
                          ⁢
                          
                            e
                            i
                          
                        
                        ⁢
                        
                          →
                          *
                        
                      
                    
                  
                
              
            
            
              
                
                  
                    λ
                    ⁢
                    
                      
                    
                    ⁢
                    
                      x
                      :
                      
                        
                          t
                          ·
                          
                            e
                            i
                            ′
                          
                        
                        ⁢
                        
                          
                        
                        ⁢
                        ∅
                      
                    
                  
                  ,
                  
                    e
                    :
                    
                      
                        t
                        ⊕
                      
                      ⊳
                      
                        
                          e
                          i
                          ′
                        
                        :
                        
                          t
                          i
                          ′
                        
                      
                    
                  
                
              
            
          
          
            
              
                
                  γ
                  (
                  
                    ⊳
                                      
                  ⁢
                  
                    
                  
                  )
                
                E
                ⊕
              
              ⁢
              
                (
                
                  
                    e
                    1
                  
                  ,
                  ...
                  ⁢
                  
                    
                  
                  ,
                  
                    e
                    n
                  
                
                )
              
            
            ∷
            
              
                t
                ⊕
              
              ⁢
                            ⁢
              
                t
                2
              
            
          
        
      
    
    
      
        [
        
          C
          ⁢
          
            -
          
          ⁢
          1
          ⁢
          b
        
        ]
      
    
  
  
    
      
        
          j
          ∈
          
            [
            
              1
              ,
              n
            
            ]
          
        
        ,
        
          j
          ≠
          
            i
            ⁢
            
              
                
                  
                    
                      
                        γ
                        ⊳
                        E
                        ∷
                        
                          t
                          1
                          ′
                        
                      
                      →
                      
                        ⋯
                        →
                        
                          
                            t
                            n
                            ′
                          
                          →
                          
                            t
                            2
                          
                        
                      
                    
                  
                
                
                  
                    
                      
                        
                          e
                          i
                        
                        ⁢
                        
                          →
                          *
                        
                        ⁢
                        
                          λ
                          ⁢
                          
                            
                          
                          ⁢
                          
                            x
                            :
                            
                              
                                t
                                ·
                                
                                  e
                                  i
                                  ′
                                
                              
                              ⁢
                              
                                
                              
                              ⁢
                              ∅
                            
                          
                        
                      
                      ,
                      
                        e
                        :
                        
                          
                            t
                            x
                          
                          ⊳
                          
                            
                              e
                              i
                              ′
                            
                            :
                            
                              t
                              i
                              ′
                            
                          
                        
                      
                    
                  
                
                
                  
                    
                      
                        
                          
                            e
                            j
                          
                          ⁢
                          
                            →
                            *
                          
                          ⁢
                          
                            fix
                            ⁢
                            
                              
                            
                            ⁢
                            
                              f
                              (
                              
                                
                              
                              ⁢
                              
                                x
                                :
                                t
                              
                              )
                            
                          
                        
                        =
                        
                          
                            e
                            j
                            ′
                          
                          ⁢
                          
                            
                          
                          ⁢
                          ∅
                        
                      
                      ,
                      
                        x
                        :
                        
                          t
                          x
                        
                      
                      ,
                      
                        f
                        :
                        
                          
                            
                              t
                              x
                            
                            ⁢
                                                        ⁢
                            
                              t
                              j
                              ′
                            
                          
                          ⊳
                          
                            
                              e
                              j
                              ′
                            
                            :
                            
                              t
                              j
                              ′
                            
                          
                        
                      
                    
                  
                
              
              
                
                  
                    
                      γ
                      (
                      
                        ⊳
                                              
                      ⁢
                      
                        
                      
                      )
                    
                    E
                    ⊕
                  
                  ⁢
                  
                    (
                    
                      
                        e
                        1
                      
                      ,
                      ...
                      ⁢
                      
                        
                      
                      ,
                      
                        e
                        n
                      
                    
                    )
                  
                
                ∷
                
                  
                    t
                    x
                  
                  ⁢
                                    ⁢
                  
                    t
                    2
                  
                
              
            
          
        
      
    
    
      
        [
        
          C
          ⁢
          
            -
          
          ⁢
          2
          ⁢
          a
        
        ]
      
    
  




E. Extending the Calculus with Imperative Expressions

E.1 Computing Environment
The computing environment, which is noted herein as S, is a stack of mappings from names (of variables) to reduced values, such that:

S::={xiv}|S,{xiv}

with xiv defining a notation for the mapping of a unique label xi into a reduced value vi, and where “S,xv” is often an abbreviation for “S,s∪{xv}”.
The transition relation now becomes S├e→S′├e′ in the general case, although invariant execution structures can be skipped for clarity when required. Informally, this relation means “expression e computed in environment S becomes e′ in environment S′”, while understanding that S′ is possibly different from S. In this new environment, previous computation e→e′ must be understood as Ø├e→Ø├e′, and previous rules comprising relations like e→e′ must be understood as S├e→S′├e′.
E.2 Syntactic Extensions
Syntactic extensions mainly introduce variable declarations, imperative control statements and procedural abstractions. Two distinguished values unit, none together with their associated types Unit, None play an important role in defining (and typing) procedural composition. Note also that the ∇-abstraction (also called “pam” for “polymorphic abstract machine”) and its recursive variant have distinct types (similar to λ-abstractions).













e ::= var x = e.e |
variable declaration


x := e | * (e) | e;e |
eassignrnent, iterarion, sequencing


e   e | [|e1,...,en|]
rule, action systems


unit | none | pop x |
special constants, internal op


∇x:t,y:t.e |
∇ procedural abstraction


fixF(x:t,y:t)=e
∇ fix point abstraction


t ::= Unit | None | t   t | t   t
Unit and None type, pam,



recursive pam









Note that “pop x” is intended to be an internal term used for defining the semantics of nabla application (as generated by the interpreter) (see [@-∇, @-∇-F]), not explicitly available for specifying computation.
E.3 Operational Semantics
The following equations describe the semantics of variable access ([var]), pop operation ([pop]), and declarations ([d1], [d2]):

S,xv├x→S,xv├v  [var]

S,s∪{xv}├ pop x→S├v  [pop]





  
    
      S
      ⊢
      
        
          e
          1
        
        →
        
          S
          ′
        
      
      ⊢
      
        e
        1
        ′
      
    
    
      
        S
        ⊢
        
          var
          ⁢
          
            
          
          ⁢
          x
        
      
      =
      
        
          
            
              
                e
                1
              
              ·
              
                e
                2
              
            
            →
            
              S
              ′
            
          
          ⊢
          
            →
            
              var
              ⁢
              
                
              
              ⁢
              x
            
          
        
        =
        
          
            e
            1
            ′
          
          ·
          
            e
            2
          
        
      
    
  
  ⁡
  
    [
    
      d
      ⁢
      
        
      
      ⁢
      1
    
    ]
  




S,s├ var x=v.e→S,s∪{xv}├e  [d2]

Assignment allows changing the value referenced by a variable as follows:




  
    
      
        
          
            S
            ⊢
            
              e
              →
              
                S
                ′
              
            
            ⊢
            
              e
              ′
            
          
          
            
              S
              ⊢
              x
            
            :=
            
              
                
                  e
                  →
                  
                    S
                    ′
                  
                
                ⊢
                x
              
              :=
              
                e
                ′
              
            
          
        
        ⁢
        
          [
          
            v
            -
            assg
          
          ]
        
      
    
    
      
        
      
    
  




S,xw├x:=v→S,xv├ unit  [v-assg]

Iteration of a statement relies on a Boolean invariant: the statement evaluates to a unit. A rule which cannot be applied evaluates to none.

*(e)→if e==unit then *(e) else unit  [iter]

e1e2→ if e1==true then e2 else none  [rule]

An action system is an ordered collection of statements. Statement i+1 is executed only if statement “i” evaluates to none.




  
    
      
        
          
            υ
            f
          
          ⁢
          
            
          
          ⁢
          fresh
        
        ,
        
          
            n
            ≥
            
              2
              ⁢
              
                
              
              [
              
                
                
                  
                    e
                    1
                  
                  ,
                  ...
                  ⁢
                  
                    
                  
                  ,
                  
                    e
                    n
                  
                
                
              
              ]
            
          
          →
          
            [
            
              
                
                  
                    
                      
                        
                          var
                          ⁢
                          
                            
                          
                          ⁢
                          
                            υ
                            f
                          
                        
                        =
                        
                          
                            e
                            1
                          
                          .
                        
                      
                      ⁢
                      
                        
                      
                    
                  
                
                
                  
                    
                      
                        if
                        ⁢
                        
                          
                        
                        ⁢
                        
                          (
                          
                            
                              υ
                              f
                            
                            ==
                            none
                          
                          )
                        
                      
                      ⁢
                      
                        
                      
                    
                  
                
                
                  
                    
                      then
                      ⁢
                      
                        
                      
                      [
                      
                        
                        
                          
                            e
                            2
                          
                          ,
                          ...
                          ⁢
                          
                            
                          
                          ,
                          
                            e
                            n
                          
                        
                        
                      
                      ]
                    
                  
                
                
                  
                    
                      
                        else
                        ⁢
                        
                          
                        
                        ⁢
                        
                          υ
                          f
                        
                      
                      ⁢
                      
                        
                      
                    
                  
                
              
              ⁢
              
                
              
              ⁢
              
                [
                AsysI
                ]
              
            
          
        
      
    
    
      
        
      
    
  




[|e|]→e  [Asys2]

A sequence of statement evaluates first its left argument.




  
    
      
        
          
            S
            ⊢
            
              
                e
                1
              
              →
              
                S
                ′
              
            
            ⊢
            
              e
              1
              ′
            
          
          
            
              S
              ⊢
              
                e
                1
              
            
            ;
            
              
                
                  e
                  2
                
                →
                
                  S
                  ′
                
              
              ⊢
              
                e
                1
                ′
              
            
            ;
            
              e
              2
            
          
        
        ⁢
        
          [
          seq1
          ]
        
      
    
    
      
        
      
    
  




v;e2→e2  [seq2]

Application on procedural abstractions creates a new store on top of the stack of mappings in the computing environment S. This store contains the input value and the output is initialized through a default value computed by init (t) from the type “t”. The result (i.e., the value of the output parameter after completion of the computation) is returned through the following pop instruction:

t2≠⊥S├∇x:t1,y:t2.e(v)→S,{xv,yinit(t2)}├e; pop y  [@-∇]

The application on recursive procedural abstractions “f” similarly creates a new store on top of the stack that contains a reference to “f” itself as follows:

t2≠⊥S├fix f(x:t1,y:t2)=e(v)→S,{ffix f(xt1,yt2)=e,xv,yinit(t2)}├e; pop y  [@-∇-F]

E.4 Type System
Additions to the type system set forth in section C include the following equations:

γunit::Unit  [Unit]

γnone::None  [None]





  
    
      
        
          
            γ
            ⊳
            x
            ∷
            t
          
          
            γ
            ⊳
            popx
            ∷
            t
          
        
        ⁡
        
          [
          Pop
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            
              
                
                  x
                  ∉
                  
                    dom
                    ⁡
                    
                      (
                      γ
                      )
                    
                  
                
              
            
            
              
                
                  
                    γ
                    ⊳
                    
                      
                        e
                        1
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      t
                      ⁢
                      
                        
                      
                      ⁢
                      γ
                    
                  
                  ,
                  
                    
                      
                        x
                        _
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      t
                    
                    ⊳
                    
                      e
                      2
                    
                    ∷
                    
                      t
                      ′
                    
                  
                
              
            
          
          
            
              γ
              ⊳
              
                var
                ⁢
                
                  
                
                ⁢
                x
              
            
            =
            
              
                
                  e
                  1
                
                ·
                
                  e
                  2
                
              
              ∷
              
                t
                ′
              
            
          
        
        ⁢
        
          [
          Dec1
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            γ
            ⊳
            
              e
              ⁢
              
                :
              
              ⁢
              t
            
          
          
            γ
            ,
            
              
                
                  
                    x
                    _
                  
                  ⁢
                  
                    :
                  
                  ⁢
                  t
                
                ⊳
                x
              
              :=
              
                e
                ∷
                Unit
              
            
          
        
        ⁢
        
          [
          Assg
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            
              
                γ
                ⊳
                e
                ∷
                Unit
              
              
            
            ⁢
            None
          
          
            γ
            ⊳
            
              *
              
                (
                e
                )
              
            
            ∷
            Unit
          
        
        ⁢
        
          [
          Iter
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            
              
                
                  γ
                  ⊳
                  
                    
                      e
                      1
                    
                    ⁢
                    
                      :
                    
                    ⁢
                    Unit
                  
                
                
              
              ⁢
              None
              ⁢
              
                
              
              ⁢
              γ
            
            ⊳
            
              e
              2
            
            ∷
            
              t
              2
            
          
          
            
              γ
              ⊳
              
                e
                1
              
            
            ;
            
              
                e
                2
              
              ∷
              
                t
                2
              
            
          
        
        ⁡
        
          [
          Seq
          ]
        
      
    
    
      
        
      
    
  




As set forth in the equation [Dec1] above, a variable name “x”is introduced into the environment with the notation “{overscore (x)}”. This is required in order to distinguish variable names from lambda parameters. With a parameter such as “y”, an operation such as “y:=e”is not well typed since the equation [Assg] requires a variable name. In the declaration [T-∇, T-∇-F], input and output parameters are introduced as variables into the environment so that they can be modified when embedded code is executed.
In the following two equations, “α” makes explicit the type of the code embedded into the abstraction. This is not used in the subtype relation (see [∇-sub1, ∇-sub2]), but in the composition operations defined later.




  
    
      
        
          t
          2
        
        ≠
        ⊥
        
          
            
              
                
                  
                    x
                    ,
                    
                      y
                      ∉
                      
                        dom
                        ⁢
                        
                          
                        
                        ⁢
                        
                          (
                          γ
                          )
                        
                        ⁢
                        
                          
                        
                        ⁢
                        γ
                      
                    
                    ,
                    
                      
                        x
                        _
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        t
                        1
                      
                    
                    ,
                  
                
              
              
                
                  
                    
                      
                        
                          
                            y
                            _
                          
                          ⁢
                          
                            :
                          
                          ⁢
                          
                            t
                            2
                          
                        
                        ⊳
                        e
                        ∷
                        
                          α
                          ⁢
                          
                            
                          
                          ⁢
                          γ
                        
                        ⊳
                        α
                        ≼
                        Unit
                      
                      
                    
                    ⁢
                    None
                  
                
              
            
            
              
                γ
                ⊳
                
                  
                    ∇
                    x
                  
                  ⁢
                  
                    :
                  
                  ⁢
                  
                    t
                    1
                  
                  ⁢
                  y
                  ⁢
                  
                    :
                  
                  ⁢
                  
                    
                      t
                      2
                    
                    .
                    e
                  
                
                ∷
                
                  t
                  1
                
              
              ⁢
              
                ⇒
                α
              
              ⁢
              
                t
                2
              
            
          
          ⁢
          
            [
            
              T
              ⁢
              
                -
              
              ∇
            
            ]
          
        
      
    
    
      
        
      
    
  
  
    
      
        
          t
          2
        
        ≠
        ⊥
        
          
            
              
                
                  
                    x
                    ,
                    y
                    ,
                    
                      f
                      ∉
                      
                        
                          dom
                          ⁡
                          
                            (
                            γ
                            )
                          
                        
                        ⁢
                        
                          
                        
                        ⁢
                        γ
                      
                    
                    ,
                    
                      
                        f
                        _
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        t
                        1
                      
                      ⁢
                      
                        
                        
                          
                            ⇒
                            α
                          
                          ⁢
                          
                            t
                            2
                          
                        
                      
                    
                  
                
              
              
                
                  
                    
                      
                        
                          
                            x
                            _
                          
                          ⁢
                          
                            :
                          
                          ⁢
                          
                            t
                            1
                          
                        
                        ,
                        
                          
                            
                              y
                              _
                            
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              t
                              2
                            
                          
                          ⊳
                          e
                          ∷
                          
                            α
                            ⁢
                            
                              
                            
                            ⁢
                            γ
                          
                          ⊳
                          α
                          ≼
                          Unit
                        
                      
                      
                    
                    ⁢
                    None
                  
                
              
            
            
              
                γ
                ⧐
                
                  
                    fix
                    ⁢
                    f
                  
                  ⁡
                  
                    (
                    
                      
                        x
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          1
                        
                      
                      ,
                      
                        y
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          2
                        
                      
                    
                    )
                  
                
              
              =
              
                e
                ∷
                
                  
                    t
                    1
                  
                  ⁢
                  
                    
                    
                      
                        ⇒
                        α
                      
                      ⁢
                      
                        t
                        2
                      
                    
                  
                
              
            
          
          ⁢
          
            [
            
              T
              ⁢
              
                -
              
              ⁢
              
                ∇
                
                  -
                
              
              ⁢
              F
            
            ]
          
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            γ
            ⊳
            
              t
              2
            
            ≼
            
              
                t
                4
              
              ⁢
              
                
              
              ⁢
              γ
            
            ⊳
            
              t
              3
            
            ≼
            
              t
              1
            
          
          
            
              γ
              ⊳
              
                t
                1
              
            
            ⁢
            
              ⇒
              α
            
            ⁢
            
              
                t
                2
              
              ≼
              
                t
                3
              
            
            ⁢
            
              ⇒
              
                α
                ′
              
            
            ⁢
            
              t
              4
            
          
        
        ⁢
        
          [
          
            
              ∇
              
                -
              
            
            ⁢
            sub1
          
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            γ
            ⊳
            
              t
              2
            
            ≼
            
              
                t
                4
              
              ⁢
              
                
              
              ⁢
              γ
            
            ⊳
            
              t
              3
            
            ≼
            
              t
              1
            
          
          
            γ
            ⊳
            
              
                t
                1
              
              ⁢
              
                
                
                  
                    ⇒
                    α
                  
                  ⁢
                  
                    
                      t
                      2
                    
                    ≼
                    
                      
                        t
                        3
                      
                      ⁢
                      
                        
                        
                          
                            ⇒
                            
                              α
                              ′
                            
                          
                          ⁢
                          
                            t
                            4
                          
                        
                      
                    
                  
                
              
            
          
        
        ⁢
        
          [
          
            
              ∇
              
                -
              
            
            ⁢
            sub2
          
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            γ
            ⊳
            
              
                e
                1
              
              ⁢
              
                :
              
              ⁢
              bool
              ⁢
              
                
              
              ⁢
              γ
            
            ⊳
            
              e
              2
            
            ∷
            t
          
          
            
              γ
              ⊳
              
                e
                1
              
            
            ⇒
            
              
                e
                2
              
              ∷
              
                t
                ⊕
                None
              
            
          
        
        ⁢
        
          [
          Rule
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            
              
                
                  γ
                  ⊳
                  
                    e
                    1
                  
                  ∷
                  
                    
                      t
                      1
                    
                    ⊕
                    
                      None
                      ⁢
                      
                        
                      
                      ⁢
                      ...
                      ⁢
                      
                        
                      
                      ⁢
                      γ
                    
                  
                  ⊳
                  
                    e
                    
                      n
                      -
                      1
                    
                  
                  ∷
                  
                    
                      t
                      
                        n
                        -
                        1
                      
                    
                    ⊕
                    None
                  
                
              
            
            
              
                
                  γ
                  ⊳
                  
                    e
                    n
                  
                  ∷
                  
                    t
                    n
                  
                
              
            
          
          
            γ
            ⊳
            
              [
              
                
                
                  
                    e
                    1
                  
                  ,
                  ...
                  ⁢
                  
                    
                  
                  ,
                  
                    e
                    n
                  
                
                
              
              ]
            
            ∷
            
              
                t
                1
              
              ⊕
              
                
              
              ⁢
              ...
              ⁢
              
                
              
              ⊕
              
                t
                n
              
            
          
        
        ⁢
        
          [
          Asys
          ]
        
      
    
    
      
        
      
    
  




F. Polymorphic Composition of ∇-Abstractions

In this section, the meta-variables *, ⋄ range over {⊕, }. A parametric function Φ performs a syntactic transformation of “n” terms into a new term.
F.1 Semantics
Defining the composition operator:




  
    
      
        
          
            
              
                Φ
                E
              
              ⁡
              
                (
                
                  
                    
                      e
                      1
                    
                    ⁡
                    
                      [
                      
                        
                          x
                          /
                          
                            x
                            1
                          
                        
                        ,
                        
                          y
                          /
                          
                            y
                            1
                          
                        
                      
                      ]
                    
                  
                  ,
                  ⋯
                  ⁢
                  
                    
                  
                  ,
                  
                    
                      e
                      n
                    
                    ⁡
                    
                      [
                      
                        
                          x
                          /
                          
                            x
                            n
                          
                        
                        ,
                        
                          y
                          /
                          
                            y
                            n
                          
                        
                      
                      ]
                    
                  
                
                )
              
            
            ⁢
                        ⁢
            e
          
          
            
              
                
                  
                                        E
                    
                      ★
                      ,
                      ⋄
                    
                  
                  ⁢
                  
                    (
                    
                      
                        
                          ∇
                          
                            x
                            1
                          
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          1
                        
                      
                      ,
                      
                        
                          y
                          1
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          
                            t
                            1
                            ′
                          
                          ·
                          
                            e
                            1
                          
                        
                      
                      ,
                      ⋯
                      ⁢
                      
                        
                      
                      ,
                    
                  
                
              
            
            
              
                
                  
                    
                      
                        
                          
                            ∇
                            
                              x
                              n
                            
                          
                          ⁢
                          
                            :
                          
                          ⁢
                          
                            t
                            n
                          
                        
                        ,
                        
                          
                            y
                            n
                          
                          ⁢
                          
                            :
                          
                          ⁢
                          
                            
                              t
                              n
                              ′
                            
                            ·
                            
                              e
                              n
                            
                          
                        
                      
                      )
                    
                    ->
                    
                      
                        ∇
                        x
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        t
                        1
                      
                      ⁢
                      ★
                      ⁢
                      
                        
                      
                      ⁢
                      ⋯
                      ⁢
                      
                        
                      
                      ⁢
                      
                        ★t
                        n
                      
                    
                  
                  ,
                  
                    y
                    ⁢
                    
                      :
                    
                    ⁢
                    
                      
                        
                          t
                          1
                          ′
                        
                        ⋄
                        
                          
                        
                        ⁢
                        ⋯
                        ⁢
                        
                          
                        
                        ⋄
                        
                          t
                          n
                          ′
                        
                      
                      ·
                      
                        e
                        n
                      
                    
                  
                
              
            
          
        
        ⁢
        
          [
          c4
          ]
        
      
    
    
      
        
      
    
  




More precisely, ΦE kinitially performs a recursive decent while it encounters variable declarations (the last variable declarations are not ignored but consistently renamed in order to avoid name clashes) and then applies “E” to the first term found. The Φ function over terms is formally defined by (ē is a notation for any term “e” which does not have the syntactic form var

x=e1.e2):

ΦE(var x1=e1.e1′, . . . en)=var xf=e1.ΦE(e′1[xf/x1], . . . en) (xf fresh)

ΦE(e{overscore ( )}1, . . . en)=Ee{overscore ( )}1ΦE(e2, . . . en)





  
    
      
        
          
            
              
                
                  
                    Φ
                    E
                  
                  (
                  
                    
                      
                        e
                        1
                      
                      ⁡
                      
                        [
                        
                          
                            x
                            /
                            
                              x
                              1
                            
                          
                          ,
                          
                            y
                            /
                            
                              y
                              1
                            
                          
                        
                        ]
                      
                    
                    ,
                    ⋯
                    ⁢
                    
                      
                    
                    ,
                    
                      
                        e
                        i
                      
                      ⁡
                      
                        [
                        
                          
                            F
                            /
                            
                              f
                              i
                            
                          
                          ,
                          
                            x
                            /
                            
                              x
                              i
                            
                          
                          ,
                          
                            y
                            /
                            
                              y
                              i
                            
                          
                        
                        ]
                      
                    
                    ,
                    ⋯
                    ⁢
                    
                      
                    
                    ,
                  
                
              
            
            
              
                
                  
                    
                      
                        e
                        n
                      
                      ⁡
                      
                        [
                        
                          
                            x
                            /
                            
                              x
                              n
                            
                          
                          ,
                          
                            y
                            /
                            
                              y
                              n
                            
                          
                        
                        ]
                      
                    
                    )
                  
                  ⁢
                  
                                        ∘
                    
                      
                    
                    ⁢
                    e
                  
                
              
            
          
          
            
              
                
                  
                                        E
                    
                      ★
                      ,
                      ⋄
                    
                  
                  ⁢
                  
                    (
                    
                      
                        
                          ∇
                          
                            x
                            1
                          
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          1
                        
                      
                      ,
                      
                        
                          y
                          1
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          
                            t
                            1
                            ′
                          
                          ·
                          
                            e
                            1
                          
                        
                      
                      ,
                      ⋯
                      ⁢
                      
                        
                      
                      ,
                      
                        
                          fix
                          ⁢
                          
                            
                              
                            
                            ⁢
                            
                              
                            
                          
                          ⁢
                          
                            
                              f
                              i
                            
                            ⁡
                            
                              (
                              
                                
                                  
                                    x
                                    i
                                  
                                  ⁢
                                  
                                    :
                                  
                                  ⁢
                                  
                                    t
                                    i
                                  
                                
                                ,
                                
                                  
                                    y
                                    i
                                  
                                  ⁢
                                  
                                    :
                                  
                                  ⁢
                                  
                                    t
                                    i
                                  
                                
                              
                              )
                            
                          
                        
                        =
                        
                          e
                          i
                        
                      
                      ,
                      ⋯
                      ⁢
                      
                        
                      
                      ,
                    
                  
                
              
            
            
              
                
                  
                    
                      
                        
                          
                            ∇
                            
                              x
                              n
                            
                          
                          ⁢
                          
                            :
                          
                          ⁢
                          
                            t
                            n
                          
                        
                        ,
                        
                          
                            y
                            n
                          
                          ⁢
                          
                            :
                          
                          ⁢
                          
                            
                              t
                              n
                              ′
                            
                            ·
                            
                              e
                              n
                            
                          
                        
                      
                      )
                    
                    ->
                    
                      fix
                      ⁢
                      
                        
                      
                      ⁢
                      
                        F
                        (
                        
                          
                            x
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              t
                              ★
                            
                          
                          ,
                          
                            y
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              t
                              
                                ′
                                ⋄
                              
                            
                          
                        
                        )
                      
                    
                  
                  =
                  e
                
              
            
          
        
        ⁢
        
          [
          c5
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            t
            1
            ′
          
          ⁢
          
            ★t
            2
          
        
        ≠
        ⊥
        
          
            
              
                
                  Φ
                  E
                
                ⁡
                
                  (
                  
                    
                      
                        e
                        1
                      
                      ⁡
                      
                        [
                        
                          x
                          /
                          
                            y
                            1
                          
                        
                        ]
                      
                    
                    ,
                    
                      
                        e
                        2
                      
                      ⁡
                      
                        [
                        
                          x
                          /
                          
                            x
                            2
                          
                        
                        ]
                      
                    
                  
                  )
                
              
              ⁢
              
                                ∘
                
                  
                
                ⁢
                e
              
            
            
              
                
                  
                    
                                            ⁢
                      
                        (
                        
                          
                            
                              ∇
                              
                                
                              
                              ⁢
                              
                                x
                                1
                              
                            
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              t
                              1
                            
                          
                          ,
                          
                            
                              y
                              1
                            
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              
                                t
                                1
                                ′
                              
                              ·
                              
                                e
                                1
                              
                            
                          
                          ,
                          
                            
                              ∇
                              
                                
                              
                              ⁢
                              
                                x
                                2
                              
                            
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              t
                              2
                            
                          
                          ,
                          
                            
                              y
                              2
                            
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              
                                t
                                2
                                ′
                              
                              ·
                              
                                e
                                2
                              
                            
                          
                        
                        )
                      
                    
                    ->
                  
                
              
              
                
                  
                    
                      
                        ∇
                        
                          
                        
                        ⁢
                        
                          x
                          1
                        
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        t
                        1
                      
                    
                    ,
                    
                      
                        
                          y
                          2
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          
                            t
                            2
                            ′
                          
                          ·
                          var
                        
                        ⁢
                        
                          
                        
                        ⁢
                        x
                      
                      =
                      
                        
                          init
                          ⁡
                          
                            (
                            
                              
                                t
                                1
                                ′
                              
                              ⁢
                              
                                ★t
                                2
                              
                            
                            )
                          
                        
                        ·
                        e
                      
                    
                  
                
              
            
          
          ⁢
          
            [
            c6
            ]
          
        
      
    
    
      
        
      
    
  




and with:

Iterλx:Unit|None.*(x)





  
    
      
        
          
            
              
                Φ
                Iter
              
              ⁡
              
                (
                e
                )
              
            
            ⁢
            
                            ∘
              
                
              
              ⁢
              
                e
                ′
              
            
          
          
            
              
                                ⁢
                
                  (
                  
                    
                      
                        ∇
                        x
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      t
                    
                    ,
                    
                      y
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        
                          t
                          ′
                        
                        ·
                        e
                      
                    
                  
                  )
                
              
              ->
              
                
                  ∇
                  x
                
                ⁢
                
                  :
                
                ⁢
                t
              
            
            ,
            
              y
              ⁢
              
                :
              
              ⁢
              
                
                  t
                  ′
                
                ·
                
                  e
                  ′
                
              
            
          
        
        ⁢
        
          [
          c7
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            
              
                Φ
                Iter
              
              ⁡
              
                (
                e
                )
              
            
            ⁢
            
                            ∘
              
                
              
              ⁢
              
                e
                ′
              
            
          
          
            
              
                                ⁢
                
                  (
                  
                    
                      fix
                      ⁢
                      
                        
                      
                      ⁢
                      
                        f
                        ⁡
                        
                          (
                          
                            
                              x
                              ⁢
                              
                                :
                              
                              ⁢
                              t
                            
                            ,
                            
                              y
                              ⁢
                              
                                :
                              
                              ⁢
                              
                                t
                                ′
                              
                            
                          
                          )
                        
                      
                    
                    =
                    e
                  
                  )
                
              
              ->
              
                fix
                ⁢
                
                  
                
                ⁢
                
                  f
                  ⁡
                  
                    (
                    
                      
                        x
                        ⁢
                        
                          :
                        
                        ⁢
                        t
                      
                      ,
                      
                        y
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          ′
                        
                      
                    
                    )
                  
                
              
            
            =
            
              e
              ′
            
          
        
        ⁡
        
          [
          c8
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            
              
                
                                    ⁢
                  
                    (
                    
                      
                        
                          ∇
                          x
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        t
                      
                      ,
                      
                        y
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          
                            t
                            ′
                          
                          ·
                          e
                        
                      
                    
                    )
                  
                
                ->
                
                  
                    ∇
                    y
                  
                  ⁢
                  
                    :
                  
                  ⁢
                  
                    t
                    ′
                  
                
              
              ,
              
                x
                ⁢
                
                  :
                
                ⁢
                
                  t
                  ·
                  e
                
              
            
            _
          
          ⁡
          
            [
            c9
            ]
          
        
        ⁢
        
          

        
        ⁢
        
          
        
      
    
    
      
        
      
    
  
  
    
      
        
        ⁢
        
          
            
              
                
                                    ⁢
                  
                    (
                    
                      
                        fix
                        ⁢
                        
                          
                        
                        ⁢
                        
                          f
                          ⁡
                          
                            (
                            
                              
                                x
                                ⁢
                                
                                  :
                                
                                ⁢
                                t
                              
                              ,
                              
                                y
                                ⁢
                                
                                  :
                                
                                ⁢
                                
                                  t
                                  ′
                                
                              
                            
                            )
                          
                        
                      
                      =
                      e
                    
                    )
                  
                
                ->
                
                  fix
                  ⁢
                  
                    
                  
                  ⁢
                  
                    f
                    ⁡
                    
                      (
                      
                        
                          y
                          ⁢
                          
                            :
                          
                          ⁢
                          
                            t
                            ′
                          
                        
                        ,
                        
                          x
                          ⁢
                          
                            :
                          
                          ⁢
                          t
                        
                      
                      )
                    
                  
                
              
              =
              e
            
            _
          
          ⁡
          
            [
            c10
            ]
          
        
      
    
    
      
        
      
    
  




F.2 Typing
In accordance with the meta symbols:
*,⋄,ε{⊕,};i,jε[1,n],i≠j, and t*=t1* . . . *tn,t′⋄=t′1⋄ . . . t′n




  
    
      
        
          t
          
            ′
            ⋄
          
        
        ≠
        ⊥
        
          
            
              
                
                  
                    
                      γ
                      ⊳
                      E
                      ∷
                      
                        α
                        1
                      
                    
                    ->
                    
                      ⋯
                      ->
                      
                        
                          α
                          n
                        
                        ->
                        α
                      
                    
                  
                
              
              
                
                  
                    
                      
                        e
                        i
                      
                      ⁢
                      
                        ->
                        *
                      
                      ⁢
                      
                        
                          ∇
                          x
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          i
                        
                      
                    
                    ,
                    
                      y
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        
                          t
                          i
                          ′
                        
                        ·
                        
                          e
                          i
                          ′
                        
                      
                      ⁢
                      
                        
                      
                      ⁢
                      γ
                    
                    ,
                    
                      
                        x
                        _
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        t
                        ★
                      
                    
                    ,
                    
                      
                        
                          y
                          _
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          
                            ′
                            ⋄
                          
                        
                      
                      ⊳
                      
                        e
                        i
                        ′
                      
                      ∷
                      
                        α
                        i
                      
                    
                  
                
              
            
            
              γ
              ⊳
              
                
                                    E
                  
                    ★
                    ,
                    ⋄
                  
                
                ⁢
                
                  (
                  
                    
                      e
                      1
                    
                    ,
                    ⋯
                    ⁢
                    
                      
                    
                    ,
                    
                      e
                      n
                    
                  
                  )
                
              
              ∷
              
                
                  t
                  ★
                
                ⁢
                
                  ⟹
                  α
                
                ⁢
                
                  t
                  
                    ′
                    ⋄
                  
                
              
            
          
          ⁢
          
            [
            
              C
              -
              ∇
            
            ]
          
        
      
    
    
      
        
      
    
  
  
    
      
        
          t
          
            ′
            ⋄
          
        
        ≠
        ⊥
        
          
            
              
                
                  
                    
                      γ
                      ⊳
                      E
                      ∷
                      
                        α
                        1
                      
                    
                    ->
                    
                      ⋯
                      ->
                      
                        
                          α
                          n
                        
                        ->
                        α
                      
                    
                  
                
              
              
                
                  
                    
                      
                        e
                        i
                      
                      ⁢
                      
                        ->
                        *
                      
                      ⁢
                      
                        
                          ∇
                          x
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          i
                        
                      
                    
                    ,
                    
                      y
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        
                          t
                          i
                          ′
                        
                        ·
                        
                          e
                          i
                          ′
                        
                      
                      ⁢
                      
                        
                      
                      ⁢
                      γ
                    
                    ,
                    
                      
                        x
                        _
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        t
                        ★
                      
                    
                    ,
                    
                      
                        
                          y
                          _
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          
                            ′
                            ⋄
                          
                        
                      
                      ⊳
                      
                        e
                        i
                        ′
                      
                      ∷
                      
                        α
                        i
                      
                    
                  
                
              
              
                
                  
                    
                      
                        
                          e
                          j
                        
                        ⁢
                        
                          ->
                          *
                        
                        ⁢
                        
                          fix
                          ⁢
                          
                            
                          
                          ⁢
                          
                            
                              f
                              j
                            
                            ⁡
                            
                              (
                              
                                
                                  x
                                  ⁢
                                  
                                    :
                                  
                                  ⁢
                                  
                                    t
                                    j
                                  
                                
                                ,
                                
                                  y
                                  ⁢
                                  
                                    :
                                  
                                  ⁢
                                  
                                    t
                                    j
                                    ′
                                  
                                
                              
                              )
                            
                          
                        
                      
                      =
                      
                        
                          e
                          j
                          ′
                        
                        ⁢
                        
                          
                        
                        ⁢
                        γ
                      
                    
                    ,
                    
                      
                        x
                        _
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        t
                        ★
                      
                    
                    ,
                  
                
              
              
                
                  
                    
                      
                        y
                        _
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        t
                        
                          ′
                          ⋄
                        
                      
                    
                    ,
                    
                      
                        
                          
                            f
                            _
                          
                          j
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          ★
                        
                        ⁢
                                                ⁢
                        
                          t
                          
                            ′
                            ⋄
                          
                        
                      
                      ⊳
                      
                        e
                        j
                        ′
                      
                      ∷
                      
                        α
                        j
                      
                    
                  
                
              
            
            
              γ
              ⊳
              
                
                                    E
                  
                    ★
                    ,
                    ⋄
                  
                
                ⁢
                
                  (
                  
                    
                      e
                      1
                    
                    ,
                    ⋯
                    ⁢
                    
                      
                    
                    ,
                    
                      e
                      n
                    
                  
                  )
                
              
              ∷
              
                
                  t
                  ★
                
                ⁢
                                ⁢
                
                  t
                  
                    ′
                    ⋄
                  
                
              
            
          
          ⁡
          
            [
            
              C
              -
              
                ∇
                
                  -
                  F
                
              
            
            ]
          
        
      
    
    
      
        
      
    
  
  
    
      
        
          t
          
            ′
            ⋄
          
        
        ≠
        ⊥
        
          
            
              
                
                  
                    
                      γ
                      ⊳
                      E
                      ∷
                      
                        α
                        1
                      
                    
                    ->
                    
                      
                        α
                        2
                      
                      ->
                      α
                    
                  
                
              
              
                
                  
                    
                      
                        e
                        i
                      
                      ⁢
                      
                        ->
                        *
                      
                      ⁢
                      
                        
                          ∇
                          
                            x
                            1
                          
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          1
                        
                      
                    
                    ,
                    
                      
                        y
                        1
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        
                          t
                          1
                          ′
                        
                        ·
                        
                          e
                          1
                          ′
                        
                      
                    
                  
                
              
              
                
                  
                    γ
                    ,
                    
                      
                        
                          x
                          _
                        
                        1
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        t
                        1
                      
                    
                    ,
                    
                      
                        
                          
                            y
                            _
                          
                          1
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          1
                          ′
                        
                        ⁢
                        
                          ★t
                          2
                        
                      
                      ⊳
                      
                        e
                        1
                        ′
                      
                      ∷
                      
                        α
                        1
                      
                    
                  
                
              
              
                
                  
                    
                      
                        e
                        2
                      
                      ⁢
                      
                        ->
                        *
                      
                      ⁢
                      
                        
                          ∇
                          
                            x
                            2
                          
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          2
                        
                      
                    
                    ,
                    
                      
                        y
                        2
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        
                          t
                          2
                          ′
                        
                        ·
                        
                          e
                          2
                          ′
                        
                      
                    
                  
                
              
              
                
                  
                    γ
                    ,
                    
                      
                        
                          x
                          _
                        
                        2
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        t
                        1
                      
                    
                    ,
                    
                      ★t
                      2
                    
                    ,
                    
                      
                        
                          
                            y
                            _
                          
                          2
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          t
                          2
                        
                      
                      ⊳
                      
                        e
                        2
                        ′
                      
                      ∷
                      
                        α
                        2
                      
                    
                  
                
              
            
            
              (
              
                γ
                ⊳
                
                                    ⁢
                  
                    (
                    
                      
                        e
                        1
                      
                      ,
                      
                        e
                        2
                      
                    
                    )
                  
                
                ∷
                
                  
                    t
                    1
                  
                  ⁢
                  
                    ⟹
                    α
                  
                  ⁢
                  
                    t
                    2
                    ′
                  
                
              
              )
            
          
          ⁢
          
            [
            Pipe
            ]
          
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            γ
            ⊳
            e
            ∷
            
              t
              ⁢
              
                ⟹
                
                  Unit
                  ⁢
                  
                    
                    None
                  
                
              
              ⁢
              
                t
                ′
              
            
          
          
            γ
            ⊳
            
                            ⁢
              
                (
                e
                )
              
            
            ∷
            
              t
              ⁢
              
                ⟹
                Unit
              
              ⁢
              
                t
                ′
              
            
          
        
        ⁢
        
          [
          Iter
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            γ
            ⊳
            e
            ∷
            
              t
              ⁢
              
                                
                  Unit
                  ⁢
                  
                    
                    None
                  
                
              
              ⁢
              
                t
                ′
              
            
          
          
            γ
            ⊳
            
                            ⁢
              
                (
                e
                )
              
            
            ∷
            
              t
              ⁢
              
                                Unit
              
              ⁢
              
                t
                ′
              
            
          
        
        ⁢
        
          [
          
            Iter
            -
            F
          
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          t
          ′
        
        ≠
        ⊥
        
          
            
              γ
              ⊳
              e
              ∷
              
                
                  t
                  ′
                
                ⁢
                
                  ⟹
                  α
                
                ⁢
                t
              
            
            
              γ
              ⊳
              
                                ⁢
                
                  (
                  e
                  )
                
              
              ∷
              
                t
                ⁢
                
                  ⟹
                  α
                
                ⁢
                
                  t
                  ′
                
              
            
          
          ⁢
          
            [
            Swap
            ]
          
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            
              γ
              ⊳
              e
              ∷
              
                
                  t
                  ′
                
                ⁢
                                ⁢
                t
                ⁢
                
                  
                
                ⁢
                t
              
            
            =
            
              t
              ′
            
          
          
            γ
            ⊳
            
                            ⁢
              
                (
                e
                )
              
            
            ∷
            
              t
              ⁢
                            ⁢
              
                t
                ′
              
            
          
        
        ⁢
        
          [
          
            Swap
            -
            F
          
          ]
        
      
    
    
      
        
      
    
  




G. A Set of Composition Operators

The following table defines different combinations of composition operators. It will be appreciated that while this set has particular efficiencies, other combinations are equally possible. Note that the concurrent execution operator “∥” defined in the table below is disclosed in U.S. patent application Ser. No. 10/046,191, entitled “Bi-Valuation Of Programming Statements”, which is incorporated herein by reference. In the table, the column with the heading “definition of E” defines the composition pattern of the composition operator defined in the column with the heading “operator”.













Circus

definition 



syntax
E
of E(U N = Unit|None)
operator







e1 Then e2
Then
λx:U N.λy:U N.if x ==
 (e1, e2)




unit then y else none


e1 Else e2
Else
λx:U N.λy:U N.if x ==
 (e1, e2)




none then y else unit


e1 Before e2
Before
λx:U N.λy:U N.x;y
 (e1, e2)


e1 Duringa e2
During
λx:U N.λy:U N.x∥y
 (e1, e2)


If e1 Then e2
Test
λx:U N.λy:U N.
 (e1,e2, e3)


Else e3

λz:U N.if x == unit then




y else z


e1 PThen e2
Then
λx:U N.λy:U N.if x ==
 (e1, e2)




unit then y else none


e1 PElse e2
Else
λx:U N.λy:U N.if x ==
 (e1, e2)




none then y else unit


e1 PBefore e2
Before
λx:U N.λy:U N.x;y
 (e1, e2)


*(e)
n. a.
n. a.
 (e)









Note that the second section of the table above defines operations which are polymorphic with respect to the application. For instance, if e:t1t2 and e′:t′1t,2 then, the composition (assuming it is well typed) e PBefore e′ has a type t1⊕t′1t2t′2 which is a subtype of both original types by property of ⊕ and :




  
    
      
        
          
            
              
                t
                2
              
              ⊗
              
                t
                2
                ′
              
            
            ≼
            
              
                t
                2
              
              ⁢
              
                
              
              ⁢
              
                t
                1
              
            
            ≼
            
              
                t
                1
              
              ⊕
              
                t
                1
                ′
              
            
          
          
            
              
                t
                1
              
              ⊕
              
                
                  t
                  1
                  ′
                
                ⁢
                                ⁢
                
                  
                    t
                    2
                  
                  ⊗
                  
                    t
                    2
                    ′
                  
                
              
            
            ≼
            
              
                t
                1
              
              ⁢
                            ⁢
              
                t
                2
              
            
          
        
        ⁢
        
          [
          
            
              ∇
              
                -
                sub
              
            
            ⁢
            
              
            
            ⁢
            2
          
          ]
        
      
    
    
      
        
      
    
  
  
    
      
        
          
            
              
                t
                2
              
              ⊗
              
                t
                2
                ′
              
            
            ≼
            
              
                t
                2
                ′
              
              ⁢
              
                
              
              ⁢
              
                t
                1
                ′
              
            
            ≼
            
              
                t
                1
              
              ⊕
              
                t
                1
                ′
              
            
          
          
            
              
                t
                1
              
              ⊕
              
                
                  t
                  1
                  ′
                
                ⁢
                                ⁢
                
                  
                    t
                    2
                  
                  ⊗
                  
                    t
                    2
                    ′
                  
                
              
            
            ≼
            
              
                t
                1
                ′
              
              ⁢
                            ⁢
              
                t
                2
                ′
              
            
          
        
        ⁢
        
          [
          
            
              ∇
              
                -
                sub
              
            
            ⁢
            
              
            
            ⁢
            2
          
          ]
        
      
    
    
      
        
      
    
  




This is an interesting property from the polymorphic reuse point of view. In particular, this property is required for the composition of recursive parameters since it guarantees the re-entrance of the fix point (from the type checking point of view).
The following table sets forth typing rules (i.e., type combination relations) of formal parameters for composition operators and functional abstractions, in which the meta symbols are given as: *,⋄ε{⊕,}.

















operand
 *E

 















prefixes
example
arity
result
arity
result







λ
λx:t.e
n
lambda
1
λ-fix



λ-fix
fixf(x:t) = e
n
λ-fix
—
—



mixed

n
λ-fix
—
—










The following table sets forth typing rules (i.e., type combination relations) of formal parameters for composition operators and procedural abstractions, in which the meta symbols are given as: *,⋄ε{⊕,}.














operand
 
 
 
 
















prefixes
examples
arity
result
arity
result
arity
result
arity
result





∇
∇x:t1,y:t2.e
n
∇
1
∇
1
∇
2
∇


∇-fix point
fixf(x:t1,y:t2)=e
n
∇-fix
1
∇-fix
1
∇-fix
—
—


mixed
—
n
∇-fix
—
—
—
—
—
—









H. Safety Properties of the Calculus

This section first proves a general type preservation property for the core calculus C. Then this section sets forth a strong type soundness on a restricted functional calculus F (called the core calculus: without fix point construction). Subsequently this section sets forth a weak soundness on C/F(E), a subset of C obtained by restricting composition patterns E to F.
H.1 General Type Preservation Property
Definition 5: Soundness of an execution environment S with respect to a typing environment γ, (written |├S:γ) is given by:

|├S:γ iff ∀xvεS, γx::t and γv::t

Theorem 1: Type preservation (subject reduction):

for all e,γ,S, such that γe::t and |├S:γ

then S ├e→S′├e′ implies γe′::t and |├S′:γ

Proof: Uses a structural induction. All typing cases for progressing terms are considered.
H.2 Strong Type Soundness of the Core Calculus
Lemma 1: Reduction steps decrease the complexity of terms. (Given a relevant complexity measure of terms,

|.|:F→Nat, then if e→e′, then |e′|<|e|).

Proof: As no fix point constructions are allowed, it can be shown that each computation step reduces the complexity of the term (this uses an inductive structural complexity measurement function such that |e|>0 (e is not a value and |v|=0).
Theorem 2: Progression of well typed terms e of F. (if Øe:t then if e is not a value, e→e′).
Proof: Uses a structural induction. All typing cases are considered.
Theorem 3: Strong type soundness for F. (For all term Øe, if e:t then ev)
Proof: If e is a value, then the proof is obvious. Otherwise, the progress theorem 2 insure that e will evolve, and the type preservation theorem says that it preserves the type. Lemma 1 says that each intermediate term has a complexity that decreases down to zero (value).
H.3 Weak Type Soundness of the Whole Calculus C/F( E)
The calculus C/F(E) is weakly sound, which means that for a given term e that is well typed in a given environment, if the computation of e in a valid execution environment terminates, then the result is necessarily a value.
Theorem 4: Progression of well typed terms:
for all e,γ,S such that γe:t, |├S:γ
then if e is not a value, necessarly S├e→S′├e′
Proof: In this proof the technical difficulty relies in the computation of composition operators, since the numerators of [c1] and [c2] must be themselves terminating computations. This means that the transition c1, c2 might never occur (i.e., it may be stuck in a state) if the computation is endless. But as E is a term of F, then the strong soundness theorem 3 guarantees the termination, thus the transitions c1 and c2.
Corollary 1: Well typed closed normal terms are values:
if γe:t,|├S:γ and S├e, then e is a value.
Proof: It is made by showing logical equivalence of the progress theorem 4. This last theorem 4 can be written under the propositional form a⊥bc and our corollary as a⊥cb, where a is “Øe:t”, b is “e is not a value” and c is “e→e′”. By rewriting the implications, the first form is equivalent to c) and the second to (a⊥c⊥c). This is easily amenable to (a⊥b⊥c).
Theorem 5: Weak type soundness of C/F(E):
For all e,γ,S, if γe:t, |├S:γ and S├eS′├e′ , then e′ is a value
Proof: By induction on the length “i” of the derivation path ee′ and by considering two cases: e is a value (is an obvious proof), and e is not a value. In the case e is not a value, the progress theorem 4 says that there is a transition step, and the subject reduction (theorem 1) says that the derived term is well typed. This reasoning can be iterated until the final form is reached. At this point, the corollary 1 raises the expected result.
I. Polymorphic Composition of Records
This section illustrates the benefits of composing record data structures and associated types. Records are well known as a powerful modeling tool.
I.1 Definition
The following definitions illustrate how to build record terms and how to access a record having a name “m”.
Definition 6: Syntax Of Expression “e” And Type “t”













e ::= <m1=e1,...,mn=en>
a record term, with mi as member names


::= e.m
acces to the content of member “m”


t ::= <m1:t1,...,mn:tn>
record types









Records can be understood as composite data structures in which sub-elements are stored under a labeled identifier. This offers order insensitive, easy to memorize ways of handling structured information, both from the storage and access point of view. For example defining:
Person<name: string, firstname: string>
allows the modeling of a person such as (note the order is not of importance in this instance):
Jo<firstname: ‘John’, name: ‘Doe’>
In addition, as is known in the art, subtype relations may be defined on record data types. The following record type illustrates an example of a subtype relation while remaining consistent when reading and writing to access members:
















  
    AwardWinner
    ⁢
    
      =
      def
    
    ⁢
    
      <
      
        name
        ⁢
        
          :
        
        ⁢
        
          
        
        ⁢
        string
      
    
  
  ,
  
    firstname
    ⁢
    
      :
    
    ⁢
    
      
    
    ⁢
    string
  
  ,
  
    
      prize
      ⁢
      
        :
      
      ⁢
      
        
      
      ⁢
      string
    
    >
  






 


This record type continues to allow modeling of person and


member access:


 






  
    P1
    ⁢
    
      =
      def
    
    ⁢
    
      
        ∇
        p
      
      ⁢
      
        :
      
      ⁢
      
        
      
      ⁢
      Person
    
  
  ,
  
    s
    ⁢
    
      :
    
    ⁢
    
      
    
    ⁢
    
      string
      ⁢
      
        
      
      .
      
        (
        
          s
          :=
          
            
          
          ⁢
          
            
              p
              .
              
                
              
              ⁢
              firstname
            
            ⁢
            
              +
              
                
                  
                
                ⁢
                ′′′′
              
            
            ⁢
            
              +
              
                
              
              ⁢
              
                p
                .
                
                  
                
                ⁢
                name
              
            
          
        
        )
      
    
  






 


with for example Jo, Do, and Ro:


 






  
    
      
        
          
            
              Do
              ⁢
              
                =
                def
              
              ⁢
              
                
                  <
                  name
                
                =
                
                  “
                  Knuth
                  ”
                
              
            
            ,
            
              firstname
              =
              
                “
                Donald
                ”
              
            
            ,
            
              

            
            ⁢
            
              prize
              =
              
                
                  “
                  
                    Alan
                    ⁢
                    
                      
                    
                    ⁢
                    Turing
                    ⁢
                    
                      
                    
                    ⁢
                    Award
                  
                  ”
                
                >
              
            
          
        
      
      
        
          
            
              Ro
              ⁢
              
                =
                ref
              
              ⁢
              
                
                  <
                  firstname
                
                =
                
                  “
                  Robin
                  ”
                
              
            
            ,
            
              name
              =
              
                “
                Milner
                ”
              
            
            ,
            
              

            
            ⁢
            
              prize
              =
              
                
                  “
                  
                    Alan
                    ⁢
                    
                      
                    
                    ⁢
                    Turing
                    ⁢
                    
                      
                    
                    ⁢
                    Award
                  
                  ”
                
                >
              
            
          
        
      
    
     
  
   






 


Definition 7: Record Typing






  
    
      γ
      ⊳
      
        
          
            e
            1
          
          ⁢
          ::
          ⁢
          
            
          
          ⁢
          
            t
            1
          
        
        ⁢
        
          
        
        ⁢
        ...
        ⁢
        
          
        
        ⁢
        γ
      
      ⊳
      
        
          e
          n
        
        ⁢
        
          
        
        ⁢
        ::
        ⁢
        
          
        
        ⁢
        
          t
          n
        
      
    
    
      
        
          γ
          ⊳
          <
          
            m
            1
          
        
        =
        
          e
          1
        
      
      ,
      ...
      ,
      
        
          m
          n
        
        =
        
          
            e
            n
          
          >
          
            ::
            ⁢
            
              <
              
                
                  m
                  1
                
                :
                
                  t
                  1
                
              
            
          
        
      
      ,
      ...
      ,
      
        
          m
          n
        
        :
        
          
            t
            n
          
          >
        
      
    
  
  ⁡
  
    [
    Rec
    ]
  






 


Definition 8: Record Subtyping:






  
    
      
        ∀
        
          
            m
            i
          
          ⁢
          
            
          
          ⁢
          
            ∃
            
              m
              j
              ′
            
          
        
      
      =
      
        
          m
          i
        
        |
        
          γ
          ⊳
          
            t
            i
          
          ≼
          
            t
            j
            ′
          
        
      
    
    
      
        γ
        ⊳
        <
        
          
            m
            1
          
          :
          
            t
            1
          
        
      
      ,
      ...
      ,
      
        
          m
          n
        
        :
        
          
            t
            n
          
          >
          ≼
          <
          
            
              m
              1
              ′
            
            :
            
              t
              1
              ′
            
          
        
      
      ,
      ...
      ,
      
        
          m
          k
          ′
        
        :
        
          
            t
            k
          
          >
        
      
    
  
  ⁡
  
    [
    
      S
      ⁢
      
        -
      
      ⁢
      Rec
    
    ]
  






 


Note that dom(< m1:t1, . . ., mn:tn>) = {m1, . . ., mn}


Property 1: Intersection of record types:






  
    
      
        
          
            
              
                
                  ∀
                  R
                
                ,
                
                  R
                  ′
                
              
            
          
          
            
              
                
              
            
          
        
      
      
        
          
            
          
          ⁢
          
            {
            
              
                
                  
                    
                      R
                      =
                      
                        <
                        
                          
                            m
                            1
                          
                          :
                          
                            t
                            1
                          
                        
                      
                    
                    ,
                    ...
                    ,
                    
                      
                        m
                        n
                      
                      :
                      
                        
                          t
                          n
                        
                        >
                      
                    
                  
                
              
              
                
                  
                    
                      
                        R
                        ′
                      
                      =
                      
                        <
                        
                          
                            m
                            1
                          
                          :
                          
                            t
                            1
                          
                        
                      
                    
                    ,
                    ...
                    ,
                    
                      
                        m
                        k
                      
                      :
                      
                        
                          t
                          k
                        
                        >
                      
                    
                  
                
              
            
          
        
      
    
  
   






 


then


 






  
    
      R
      ⊗
      
        R
        ′
      
    
    =
    
      <
      
        
          m
          i
        
        :
        
          
            t
            i
          
          ⊗
          
            t
            i
            ′
          
        
      
    
  
  ,
  
    
      m
      l
    
    :
    
      t
      l
    
  
  ,
  
    
      m
      p
    
    :
    
      
        t
        p
        ′
      
      >
    
  






 


with all mi, ml, mp such that


 






  
    
      
        
          
            
              m
              i
            
            ∈
            
              
                dom
                ⁡
                
                  (
                  R
                  )
                
              
              ⋂
              
                dom
                ⁡
                
                  (
                  
                    R
                    ′
                  
                  )
                
              
            
          
          ,
        
      
    
    
      
        
          
            
              m
              l
            
            ∈
            
              
                dom
                ⁡
                
                  (
                  R
                  )
                
              
              ⁢
              \
              ⁢
              
                dom
                ⁡
                
                  (
                  
                    R
                    ′
                  
                  )
                
              
            
          
          ,
        
      
    
    
      
        
          
            m
            p
          
          ∈
          
            
              dom
              ⁡
              
                (
                
                  R
                  ′
                
                )
              
            
            ⁢
            \
            ⁢
            
              dom
              ⁡
              
                (
                R
                )
              
            
          
        
      
    
  
   













Proof: Performed by application of [S-Rec].
I.2 Using Record Polymophism in Pam Composition
Let PrizeWinner be: <name: string, year: int, prize: string>
then the Property 1 in Section I.1 provides that Person  PrizeWinner is:
<firstname: string, name: string, year: int, prize: string>
which is a record type that models information found in both initial records. This is particularly useful because composition using the  operator permits extension of the signature thereby enriching the computational environment. Defined below is a pam P2 that computes a string representation of prize winner:
∇w: PrizeWinner, s:string.s:=s+w.name+“won the”+w.prize+“prize in”+w.year
Now P2(<name=“Milner”, year=“1991”, prize=“Alan Turing Award”)
will return: “Milner won the Alan Turing Award prize in 1991.”
with the following composition:

P∇x:T,y:string.(y:=y+“:”)

P3P1 Before P Before P2 

Note also the type P3 is defined as:

∅P3::PersonPriceWinnerstring

EXAMPLE 1 
P3(<name=“Milner”, year=“1991, firstname=“Robin”, prize=“Alan Turing Award”>
will return: “Robin Milner: Milner won the Alan Turing Award prize in 1991”.
As shown in this example, both P1 and P2 operate with different record types while their composition operates with a mixture of both records. In addition, the example is formally well typed. For instance, proposing an integer value for year (e.g., the integer 1991 instead of the string “1991”) would prevent finding a type for this example.
J. Illustration of a Modeling Tree Transformer
This section uses pattern matching expressions described in U.S. patent application Ser. No. 10/046,314, entitled “Symmetrical Structural Pattern Matching”, which is incorporated herein by reference. For example, the syntactic notation e1#fe2 evaluates to expression e2 if the result of expression e1 matches against the filter f; otherwise, the rule evaluates to the distinguished value none.
Filters can be recursively constructed and thus can reach arbitrary complexity levels. For example, some basic filters are “%e” (which matches any value equal to the result of e) and “? x” (which matches any value and stores the resulting value into x). A record filter is noted <m1=f1, . . . , mn=fn> where fi are filters, and matches against any record value <m1=v1, . . . , mn=vn> if every vi matches fi.
The following recursive definition (where recursive types are assumed hereafter in this example to be handled by the type system) models binary trees where nodes are labeled by any type of value (T), and where leaves of the binary tree are strings:

β(<label:T, left:β, right:β>|string)

where such types allow for instance the modeling of syntactic trees that are found in programming languages. For example as shown in FIG. 5, the arithmetic expression “a=b+10* c” can be encoded as a binary tree syntactically at 502 and illustratively at 504.
The following abstraction of a “top-down recursive tree visitor” does not perform any transformation but instead visits all nodes and reconstructs an identical tree:













V =
fixV(x:β,y:β)=[|









x ♯ <label=?lab, left=?l, right=?r>  



y :=<label=lab, left=V(l), right=V(r)>,



y := x









|]









The following transformer A changes “+” labels in a binary tree into the numeric code ADD:

t1=fix T1(x:β,y:β)=(x#<label=% “+”, left=?l, right=?r>y:=<label=Add, left=T1(l), right=T1(r)>)

A=t1 else V

FIG. 6 illustrates the resulting binary tree syntactically at 602 and illustratively at 604 when the transformer A is applied to the binary tree shown in FIG. 5.
The following transformer B changes “*” labels into the numeric code MUL:

t2=fixT2(x:β,y:β)=(x#<label=% “*”, left=?l, right=?r>  y:=<label=MUL, left=T2(l), right=T2(r)>)

B=t2 else V

FIG. 7 illustrates the resulting binary tree syntactically at 702 and illustratively at 704 when the transformer B is applied to the binary tree shown in FIG. 5.
The composition of the transformers A and B is defined as:

A∘B=∇x:β,y:β.y:=B(A(x))

Using the composition operator “else” defined in Section G above, the composition of the transformers A and B is defined as:

A∘B=t1 else t2 else V

which is computationally equivalent to:

fixT(x:β,y:β)=[|

x#<label=%“+”, left=?l, right=?r>y:=<label=ADD, left=T(l), right=T(r)>,

x#<label=%“*”, left=?l, right=?r>y:=<label=MUL, left=T(l), right=T(r)>,

x#<label=?lab, left=?l, right=?r>y:=<label=lab, left=T(l), right=T(r)>,

y:=x|]

FIG. 8 illustrates the resulting binary tree syntactically at 802 and illustratively at 804 when the composition of transformers A and B is applied to the binary tree shown in FIG. 5.
K. Miscellaneous
Using the foregoing specification, the invention may be implemented as a machine (or system), process (or method), or article of manufacture by using standard programming and/or engineering techniques to produce programming software, firmware, hardware, or any combination thereof.
Any resulting program(s), having computer-readable program code, may be embodied within one or more computer-usable media such as memory devices or transmitting devices, thereby making a computer program product or article of manufacture according to the invention. As such, the terms “article of manufacture” and “computer program product” as used herein are intended to encompass a computer program existent (permanently, temporarily, or transitorily) on any computer-usable medium such as on any memory device or in any transmitting device.
Executing program code directly from one medium, storing program code onto a medium, copying the code from one medium to another medium, transmitting the code using a transmitting device, or other equivalent acts may involve the use of a memory or transmitting device which only embodies program code transitorily as a preliminary or final step in making, using, or selling the invention.
Memory devices include, but are not limited to, fixed (hard) disk drives, floppy disks (or diskettes), optical disks, magnetic tape, semiconductor memories such as RAM, ROM, Proms, etc. Transmitting devices include, but are not limited to, the Internet, intranets, electronic bulletin board and message/note exchanges, telephone/modem based network communication, hard-wired/cabled communication network, cellular communication, radio wave communication, satellite communication, and other stationary or mobile network systems/communication links.
A machine embodying the invention may involve one or more processing systems including, but not limited to, CPU, memory/storage devices, communication links, communication/transmitting devices, servers, I/O devices, or any subcomponents or individual parts of one or more processing systems, including software, firmware, hardware, or any combination or subcombination thereof, which embody the invention as set forth in the claims.
It will be appreciated that various other alternatives, modifications, variations, improvements or other such equivalents of the teachings herein that may be presently unforeseen, unappreciated or subsequently made by others are also intended to be encompassed by the claims.

## Claims

1. A method for composing programming abstractions, comprising:
defining a composition operation for composing a first abstraction and a second abstraction with a selected composition operator; each abstraction having a form, a prefix, and at least one expression;
unfolding the expressions from the first and the second abstractions by: (a) removing the prefix of each abstraction, and (b) substituting formal parameter names in each expression with a common parameter name to define open variables;
transforming the unfolded expressions to a reduced expression using a composition pattern that tunes semantics of the selected composition operator;
selecting a prefix that depends on the selected composition operator and the form of the first abstraction and the second abstraction; the selected prefix having a formal parameter with a type; and
nesting the reduced expression in a third abstraction that composes the first abstraction and the second abstraction by: (i) appending the selected prefix to the reduced expression, (ii) binding the open variables of the reduced expression to the formal parameter of the selected prefix, and (iii) computing the type of the formal parameter of the selected prefix.

2. The method according to claim 1, wherein the selected composition operator applies to operands that comprise at least one recursive functional abstraction.

3. The method according to claim 1, wherein the selected composition operator is  as defined by:




  
    
      
        
          (
          
            z
            ⁢
            
              
            
            ⁢
            fresh
          
          )
        
        ⁢
        
          
            E
            ⁢
                        ⁢
            
              
                e
                1
              
              ⁡
              
                [
                
                  z
                  /
                  
                    x
                    1
                  
                
                ]
              
            
            ⁢
                        ⁢
            ⋯
            ⁢
            
              
            
            ⁢
                        ⁢
            
              
                e
                n
              
              ⁡
              
                [
                
                  z
                  /
                  
                    x
                    n
                  
                
                ]
              
            
            ⁢
                        ⁢
                        ⁢
            e
          
          
            
                            ⁢
              
                (
                
                  
                    λ
                    ⁢
                    
                      
                    
                    ⁢
                    
                      x
                      1
                    
                    ⁢
                    
                      :
                    
                    ⁢
                    
                      
                        t
                        1
                      
                      ·
                      
                        e
                        1
                      
                    
                  
                  ,
                  ...
                  ⁢
                  
                    
                  
                  ,
                  
                    λ
                    ⁢
                    
                      
                    
                    ⁢
                    
                      x
                      n
                    
                    ⁢
                    
                      :
                    
                    ⁢
                    
                      
                        t
                        n
                      
                      ·
                      
                        e
                        n
                      
                    
                  
                
                )
              
            
            →
            
              λ
              ⁢
              
                
              
              ⁢
              z
              ⁢
              
                :
              
              ⁢
              
                
                  t
                  x
                
                ·
                e
              
            
          
        
        ⁢
        
          [
          c1
          ]
        
      
    
    
      
        
      
    
  




where:
“λxn:tn.en” is a lambda abstraction with prefix “λx:t”, in which “λ” identifies a form of abstraction, “x” identifies a formal parameter of type “t”, and “e” is the expression of the abstraction;
“e[z/x]” means substitute xn for z in the expression en,
“” means the terminal form of an operation reduces to a value,
“” identifies a type combination relation,
“e1e2” defines a lazy application in which the expression e2 is passed by a function without first being computed,
“E” is a composition pattern.

4. The method according to claim 3, wherein the selected composition operator  applies to operands that comprise at least one recursive functional abstraction.

5. The method according to claim 1, wherein the selected composition operator is  as defined by:


(f fresh)(λx:t.e)→fix f(x:t)=f(e)  [c3]


where:
“λx:t.e” is a lambda abstraction with prefix “λx:t”, in which “λ” identifies a form of abstraction, “x” identifies a formal parameter of type “t”, and “e” is the expression of the abstraction;
“f” is the logical name of a function; and
“fix” identifies that the expression “e” is recursive, to permit use of itself through the logical name “f”.

6. The method according to claim 1, wherein the selected composition operator is  as defined by:




  
    
      
        
          
            t
            1
            ′
          
          ⁢
          
            ★t
            2
          
        
        ≠
        ⊥
        
          
            
              
                
                  Φ
                  E
                
                ⁡
                
                  (
                  
                    
                      
                        e
                        1
                      
                      ⁡
                      
                        [
                        
                          x
                          /
                          
                            y
                            1
                          
                        
                        ]
                      
                    
                    ,
                    
                      
                        e
                        2
                      
                      ⁡
                      
                        [
                        
                          x
                          /
                          
                            x
                            2
                          
                        
                        ]
                      
                    
                  
                  )
                
              
              ⁢
              
                                ∘
                
                  
                
                ⁢
                e
              
            
            
              
                
                  
                    
                      
                                                E
                        *
                      
                      ⁢
                      
                        (
                        
                          
                            
                              ∇
                              
                                
                              
                              ⁢
                              
                                x
                                1
                              
                            
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              t
                              1
                            
                          
                          ,
                          
                            
                              y
                              1
                            
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              
                                t
                                1
                                ′
                              
                              ·
                              
                                e
                                1
                              
                            
                          
                          ,
                          
                            
                              ∇
                              
                                
                              
                              ⁢
                              
                                x
                                2
                              
                            
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              t
                              2
                            
                          
                          ,
                          
                            
                              y
                              2
                            
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              
                                t
                                2
                                ′
                              
                              ·
                              
                                e
                                2
                              
                            
                          
                        
                        )
                      
                    
                    ->
                  
                
              
              
                
                  
                    
                      
                        ∇
                        
                          
                        
                        ⁢
                        
                          x
                          1
                        
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        t
                        1
                      
                    
                    ,
                    
                      
                        
                          y
                          2
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          
                            t
                            2
                            ′
                          
                          ·
                          var
                        
                        ⁢
                        
                          
                        
                        ⁢
                        x
                      
                      =
                      
                        
                          init
                          ⁡
                          
                            (
                            
                              
                                t
                                1
                                ′
                              
                              ⁢
                              
                                ★t
                                2
                              
                            
                            )
                          
                        
                        ·
                        e
                      
                    
                  
                
              
            
          
          ⁢
          
            [
            c6
            ]
          
        
      
    
    
      
        
      
    
  




where:
“∇x:t,y:t′.e” is a nabla abstraction with prefix “∇x:t,y:t′”, in which “∇” identifies a form of abstraction, “x” and “y” identify a parameter of type “t” and “t′” respectively, and “e” is the expression of the abstraction;
“Φ” is a parametric function that performs a syntactic transformation of n terms into a new term;
“E” is a composition pattern.

7. The method according to claim 1, wherein the selected composition operator is  as defined by:




  
    
      
        
          
            
              
                Φ
                Iter
              
              ⁡
              
                (
                e
                )
              
            
            ⁢
            
                            ∘
              
                
              
              ⁢
              
                e
                ′
              
            
          
          
            
              
                                ⁢
                
                  (
                  
                    
                      
                        ∇
                        x
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      t
                    
                    ,
                    
                      y
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        
                          t
                          ′
                        
                        ·
                        e
                      
                    
                  
                  )
                
              
              ->
              
                
                  ∇
                  x
                
                ⁢
                
                  :
                
                ⁢
                t
              
            
            ,
            
              y
              ⁢
              
                :
              
              ⁢
              
                
                  t
                  ′
                
                ·
                
                  e
                  ′
                
              
            
          
        
        ⁢
        
          [
          c7
          ]
        
      
    
    
      
        
      
    
  




where:
“∇x:t,y:t′.e” is a nabla abstraction with prefix “∇x:t,y:t′”, in which “∇” identifies a form of abstraction, “x” and “y” identify a parameter of type “t” and “t′” respectively, and “e” is the expression of the abstraction; and
“Φ” is a parametric function that performs a syntactic transformation of n terms into a new term.

8. The method according to claim 7, wherein the selected composition operator  applies to a recursive nabla abstraction.

9. The method according to claim 1, wherein the selected composition operator is  as defined by:




  
    
      
    
    
      
        
                    ⁢
          
            (
            
              
                ∇
                
                  
                
                ⁢
                
                  x
                  :
                  t
                
              
              ,
              
                y
                :
                
                  
                    t
                    ′
                  
                  .
                  e
                
              
            
            )
          
        
        →
        
          ∇
          
            y
            :
            
              t
              ′
            
          
        
      
      ,
      
        x
        :
        
          t
          .
          e
        
      
    
  
  ⁡
  
    [
    
      c
      ⁢
      
        
      
      ⁢
      9
    
    ]
  




where:
“∇x:t,y:t′.e” is a nabla abstraction with prefix “∇x:t,y:t′”, in which “∇” identifies a form of abstraction, “x” and “y” identify a parameter of type “t” and “t′” respectively, and “e” is the expression of the abstraction.

10. The method according to claim 9, wherein the selected composition operator  applies to a recursive nabla abstraction.

11. An apparatus for composing programming abstractions, comprising:
means for defining a composition operation for composing a first abstraction and a second abstraction with a selected composition operator; each abstraction having a form, a prefix, and at least one expression;
means for unfolding the expressions from the first and the second abstractions by: (a) removing the prefix of each abstraction, and (b) substituting formal parameter names in each expression with a common parameter name to define open variables;
means for transforming the unfolded expressions to a reduced expression using a composition pattern that tunes semantics of the selected composition operator;
means for selecting a prefix that depends on the selected composition operator and the form of the first abstraction and the second abstraction; the selected prefix having a formal parameter with a type; and
means for nesting the reduced expression in a third abstraction that composes the first abstraction and the second abstraction by: (i) appending the selected prefix to the reduced expression, (ii) binding the open variables of the reduced expression to the formal parameter of the selected prefix, and (iii) computing the type of the formal parameter of the selected prefix.

12. The apparatus according to claim 11, wherein the selected composition operator applies to operands that comprise at least one recursive functional abstraction.

13. The apparatus according to claim 11, wherein the selected composition operator is  as defined by:




  
    
      
        
          (
          
            z
            ⁢
            
              
            
            ⁢
            fresh
          
          )
        
        ⁢
        
          
            E
            ⁢
                        ⁢
            
              
                e
                1
              
              ⁡
              
                [
                
                  z
                  /
                  
                    x
                    1
                  
                
                ]
              
            
            ⁢
                        ⁢
            ⋯
            ⁢
            
              
            
            ⁢
                        ⁢
            
              
                e
                n
              
              ⁡
              
                [
                
                  z
                  /
                  
                    x
                    n
                  
                
                ]
              
            
            ⁢
                        ⁢
                        ⁢
            e
          
          
            
                            ⁢
              
                (
                
                  
                    λ
                    ⁢
                    
                      
                    
                    ⁢
                    
                      x
                      1
                    
                    ⁢
                    
                      :
                    
                    ⁢
                    
                      
                        t
                        1
                      
                      ·
                      
                        e
                        1
                      
                    
                  
                  ,
                  ...
                  ⁢
                  
                    
                  
                  ,
                  
                    λ
                    ⁢
                    
                      
                    
                    ⁢
                    
                      x
                      n
                    
                    ⁢
                    
                      :
                    
                    ⁢
                    
                      
                        t
                        n
                      
                      ·
                      
                        e
                        n
                      
                    
                  
                
                )
              
            
            →
            
              λ
              ⁢
              
                
              
              ⁢
              z
              ⁢
              
                :
              
              ⁢
              
                
                  t
                  x
                
                ·
                e
              
            
          
        
        ⁢
        
          [
          c1
          ]
        
      
    
    
      
        
      
    
  




where:
“λxn:tn.en” is a lambda abstraction with prefix “λ x:t”, in which “λ” identifies a form of abstraction, “x” identifies a formal parameter of type “t”, and “e” is the expression of the abstraction;
“en[z/xn]” means substitute xn for z in the expression en,
“” means the terminal form of an operation reduces to a value,
“” identifies a type combination relation,
“e1e2” defines a lazy application in which the expression e2 is passed by a function without first being computed,
“E” is a composition pattern.

14. The apparatus according to claim 13, wherein the selected composition operator  applies to operands that comprise at least one recursive functional abstraction.

15. The apparatus according to claim 11, wherein the selected composition operator is  as defined by:


(f fresh)(λx:t.e)→fix f(x:t)=f(e)  [c3]


where:
“λx:t.e” is a lambda abstraction with prefix “λx:t”, in which “λ” identifies a form of abstraction, “x” identifies a formal parameter of type “t”, and “e” is the expression of the abstraction;
“f” is the logical name of a function; and
“fix” identifies that the expression “e” is recursive, to permit use of itself through the logical name “f”.

16. The apparatus according to claim 11, wherein the selected composition operator is  as defined by:




  
    
      
        
          
            t
            1
            ′
          
          ⁢
          
            ★t
            2
          
        
        ≠
        ⊥
        
          
            
              
                
                  Φ
                  E
                
                ⁡
                
                  (
                  
                    
                      
                        e
                        1
                      
                      ⁡
                      
                        [
                        
                          x
                          /
                          
                            y
                            1
                          
                        
                        ]
                      
                    
                    ,
                    
                      
                        e
                        2
                      
                      ⁡
                      
                        [
                        
                          x
                          /
                          
                            x
                            2
                          
                        
                        ]
                      
                    
                  
                  )
                
              
              ⁢
              
                                ∘
                
                  
                
                ⁢
                e
              
            
            
              
                
                  
                    
                      
                                                E
                        *
                      
                      ⁢
                      
                        (
                        
                          
                            
                              ∇
                              
                                
                              
                              ⁢
                              
                                x
                                1
                              
                            
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              t
                              1
                            
                          
                          ,
                          
                            
                              y
                              1
                            
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              
                                t
                                1
                                ′
                              
                              ·
                              
                                e
                                1
                              
                            
                          
                          ,
                          
                            
                              ∇
                              
                                
                              
                              ⁢
                              
                                x
                                2
                              
                            
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              t
                              2
                            
                          
                          ,
                          
                            
                              y
                              2
                            
                            ⁢
                            
                              :
                            
                            ⁢
                            
                              
                                t
                                2
                                ′
                              
                              ·
                              
                                e
                                2
                              
                            
                          
                        
                        )
                      
                    
                    ->
                  
                
              
              
                
                  
                    
                      
                        ∇
                        
                          
                        
                        ⁢
                        
                          x
                          1
                        
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        t
                        1
                      
                    
                    ,
                    
                      
                        
                          y
                          2
                        
                        ⁢
                        
                          :
                        
                        ⁢
                        
                          
                            t
                            2
                            ′
                          
                          ·
                          var
                        
                        ⁢
                        
                          
                        
                        ⁢
                        x
                      
                      =
                      
                        
                          init
                          ⁡
                          
                            (
                            
                              
                                t
                                1
                                ′
                              
                              ⁢
                              
                                ★t
                                2
                              
                            
                            )
                          
                        
                        ·
                        e
                      
                    
                  
                
              
            
          
          ⁢
          
            [
            c6
            ]
          
        
      
    
    
      
        
      
    
  




where:
“∇x:t, y:t′.e” is a nabla abstraction with prefix “∇x:t,y:t′”, in which “∇” identifies a form of abstraction, “x” and “y” identify a parameter of type “t” and “t′” respectively, and “e” is the expression of the abstraction;
“Φ” is a parametric function that performs a syntactic transformation of n terms into a new term;
“E” is a composition pattern.

17. The apparatus according to claim 11, wherein the selected composition operator is  as defined by:




  
    
      
        
          
            
              
                Φ
                Iter
              
              ⁡
              
                (
                e
                )
              
            
            ⁢
            
                            ∘
              
                
              
              ⁢
              
                e
                ′
              
            
          
          
            
              
                                ⁢
                
                  (
                  
                    
                      
                        ∇
                        x
                      
                      ⁢
                      
                        :
                      
                      ⁢
                      t
                    
                    ,
                    
                      y
                      ⁢
                      
                        :
                      
                      ⁢
                      
                        
                          t
                          ′
                        
                        ·
                        e
                      
                    
                  
                  )
                
              
              ->
              
                
                  ∇
                  x
                
                ⁢
                
                  :
                
                ⁢
                t
              
            
            ,
            
              y
              ⁢
              
                :
              
              ⁢
              
                
                  t
                  ′
                
                ·
                
                  e
                  ′
                
              
            
          
        
        ⁢
        
          [
          c7
          ]
        
      
    
    
      
        
      
    
  




where:
“∇x:t,y:t′.e” is a nabla abstraction with prefix “∇x:t,y:t′”, in which “∇” identifies a form of abstraction, “x” and “y” identify a parameter of type “t” and “t′” respectively, and “e” is the expression of the abstraction; and
“Φ” is a parametric function that performs a syntactic transformation of n terms into a new term.

18. The apparatus according to claim 11, wherein the selected composition operator is  as defined by:




  
    
      
    
    
      
        
                    ⁢
          
            (
            
              
                ∇
                
                  
                
                ⁢
                
                  x
                  :
                  t
                
              
              ,
              
                y
                :
                
                  
                    t
                    ′
                  
                  .
                  e
                
              
            
            )
          
        
        →
        
          ∇
          
            y
            :
            
              t
              ′
            
          
        
      
      ,
      
        x
        :
        
          t
          .
          e
        
      
    
  
  ⁡
  
    [
    
      c
      ⁢
      
        
      
      ⁢
      9
    
    ]
  




where:
“∇x:t,y:t′.e” is a nabla abstraction with prefix “∇x:t,y:t′”, in which “∇” identifies a form of abstraction, “x” and “y” identify a parameter of type “t” and “t′” respectively, and “e ” is the expression of the abstraction.

19. An article of manufacture for use in a machine, comprising:
a memory;
instructions stored in the memory for composing programming abstractions comprising:
defining a composition operation for composing a first abstraction and a second abstraction with a selected composition operator; each abstraction having a form, a prefix, and at least one expression;
unfolding the expressions from the first and the second abstractions by: (a) removing the prefix of each abstraction, and (b) substituting formal parameter names in each expression with a common parameter name to define open variables;
transforming the unfolded expressions to a reduced expression using a composition pattern that tunes semantics of the selected composition operator;
selecting a prefix that depends on the selected composition operator and the form of the first abstraction and the second abstraction; the selected prefix having a formal parameter with a type; and
nesting the reduced expression in a third abstraction that composes the first abstraction and the second abstraction by: (i) appending the selected prefix to the reduced expression, (ii) binding the open variables of the reduced expression to the formal parameter of the selected prefix, and (iii) computing the type of the formal parameter of the selected prefix.

20. The article of manufacture according to claim 19, wherein the selected composition operator applies to operands that comprise at least one recursive functional abstraction.